我们是在子主题里写入的改变了新媒体库地址,下面是方法:
如果是要改变上传路径的话,需要改变 WordPress 的上传路径,但怎么做是有代价的,我们自己的站点图片和静态资源上传的都是另一个目录,比如 logo https://img.feibisi.com/2015/08/wxd_bbs_logo1.png
这样是方便很多,也加速了网站的访问,
代码如下:
//添加媒体库上传文件地址自定义功能
add_filter( 'upload_dir', 'custom_upload_dir' );
function custom_upload_dir( $uploads ) {
$dir = $_SERVER['DOCUMENT_ROOT'];
$upload_path = '/data/wwwroot/img.feibisi.com/';
$upload_url_path = 'https://img.feibisi.com';
if ( empty( $upload_path ) || 'wp-content/uploads' == $upload_path ) {
$uploads['basedir'] = WP_CONTENT_DIR . '/uploads';
} elseif ( 0 !== strpos( $upload_path, ABSPATH ) ) {
$uploads['basedir'] = path_join( ABSPATH, $upload_path );
} else {
$uploads['basedir'] = $upload_path;
}
$uploads['path'] = $uploads['basedir'].$uploads['subdir'];
if ( $upload_url_path ) {
$uploads['baseurl'] = $upload_url_path;
$uploads['url'] = $uploads['baseurl'].$uploads['subdir'];
}
return $uploads;
}
请修改上面的 /data/wwwroot/img.feibisi.com/
为你的自定义地址 https://img.feibisi.com
添加上之后,就需要你转移 WordPress 的 wp-content/uploads
文件夹里面的内容到你的另一个文件夹里。