简体   繁体   English

替换图像URL wordpress中的wp内容

[英]Replace wp-content in image urls wordpress

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... 我已将wp-content文件夹更改为名为stuff的文件夹,并尝试使用函数而不是SQL查询来更改现有帖子中的图像URL。

I've placed this in my function.php hoping it would work, but the images are still using the 'wp-content' folder? 我已将其放置在我的function.php中,希望它可以工作,但是图像仍在使用“ wp-content”文件夹?

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 );
});

I just needed to add the filter to the_content not the pre_option_upload_url_path . 我只需要将过滤器添加到the_content而不是pre_option_upload_url_path

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 */
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM