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('', '', $content);
    return $content;
add_filter('the_content', 'replace_phpfarmer_url');