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

  1. anthonyb
    Posted 6 years ago #

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


    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?


  2. xdesi
    Posted 6 years ago #

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


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

    Or did you use an attachment/custom field or something

  3. anthonyb
    Posted 6 years ago #

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

  4. xdesi
    Posted 6 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
    Posted 6 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