Replacing post content attachment url for wordpress new setup

Replacing post content attachment url for wordpress new setup

When working with wordpress sometime we need to copy full site content with new wordpress site setup. If you use wordpress default inport / export then all content and resource source url works fine but all image or attachment source url in content is keeping it’s old values.

To replace those old source url to new site url you can add a wordpress filter like my below given one.

Note: You need to copy uploads folder to your new server.

function replace_phpfarmer_url($content){
    $content = str_replace('http://olddomain.com/', 'http://newdomain.com/', $content);
    return $content;
}
add_filter('the_content', 'replace_phpfarmer_url');

Leave a Reply

  • (will not be published)