0

I've changed my wp-content folder to a folder called stuff and am trying to change my image urls in existing posts with a function rather than a SQL query...

I've placed this in my function.php hoping it would work, but the images are still using the 'wp-content' folder?

define('WP_UPLOADSURL', 'http://' . $_SERVER['HTTP_HOST']);
add_filter( 'pre_option_upload_url_path', function( $upload_dir_uri ){
    return str_replace( WP_UPLOADSURL . '/wp-content/', WP_UPLOADSURL . '/stuff/', $upload_dir_uri );
});

Thanks to a suggestion below, the_content works!

define('WP_UPLOADSURL', 'http://' . $_SERVER['HTTP_HOST']);
add_filter( 'the_content', function( $upload_dir_uri ){
    return str_replace( WP_UPLOADSURL . '/wp-content/', WP_UPLOADSURL . '/stuff/', $upload_dir_uri ); /* Again Change stuff */
});
  • 1
    That filter will have no effect on post content - you need the_content – TheDeadMedic Sep 17 '15 at 15:40
  • so add_filter('the_content', function(... would do it? – user1676224 Sep 17 '15 at 15:43
  • Give it a go, it should in theory. – TheDeadMedic Sep 17 '15 at 15:48
  • still not working with the_content – user1676224 Sep 17 '15 at 15:49
  • 1
    Are the URLs you're trying to replace within content output by the_content function? – Milo Sep 17 '15 at 16:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.