WordPress.org

Ready to get started?Download WordPress

Forums

Updating Embedded post image links on new url (5 posts)

  1. anthonyb
    Member
    Posted 4 years ago #

    I recently moved my wordpress installation to a new url and got everything up and running fine using this guide:

    http://codex.wordpress.org/Changing_The_Site_URL

    But the one problem I have encountered is that all of my images that were embedded in posts have an absolute url to the old site.

    How can I update these image paths without having to go into every post and editing them manually?

    Thanks,
    Anthony

  2. xdesi
    Member
    Posted 4 years ago #

    Are the images you have embedded part of the post content, like you added them in the post text editor?

    e.g

    Post Text <img src="link.jpg" /> More Post Text

    Or did you use an attachment/custom field or something

  3. anthonyb
    Member
    Posted 4 years ago #

    They would have been added via the text editor. Most likely using the Upload/Insert functionality.

  4. xdesi
    Member
    Posted 4 years ago #

    How about something like this in your functions.php

    function alter_content($content) {
    	//Set locations
    	$oldDir = 'http://www.oldsite.com/blog';
    	$newDir = 'http://www.newsite.com/blog';
    	$content = str_replace($oldDir,$newDir,$content);
    }
    add_filter('the_content', alter_content);

    This would modify the outputs of the_content before it appears on your blog, so you could change all instances of a URL to another URL say.

    I don't know if you can automatically update the contents of exisisting posts permanantly from a PHP script, or if there is a better way!

  5. Rev. Voodoo
    Volunteer Moderator
    Posted 4 years ago #

    reading through that link the OP posted....did you go through the search and replace in your database?

    right at the bottom of the page, it talks about images, and also doing a full search of your database for any remaining instances of the old url

Topic Closed

This topic has been closed to new replies.

About this Topic