wordpress multisite remove /sites/{ID}/ automatic upload url

家住魔仙堡 提交于 2019-12-06 11:10:01

First I ended up changing the core in wp-includes/functions.php in order to disable the addition:

if ( defined( 'MULTISITE' ) )
  $ms_dir = '/sites/' . get_current_blog_id();
else
  $ms_dir = '/' . get_current_blog_id();

And one line below that my hack:

$ms_dir = '';

But after a while I found this solution where one can use a hook. Example:

add_filter( 'upload_dir', 'same_upload_dir' );
function same_upload_dir( array $uploads ) {
    $baseurl = WP_CONTENT_URL . '/uploads';
    $basedir = ABSPATH . 'wp-content/uploads';
    $subdir = $uploads['subdir'];

    return array(
        'path'    => $basedir . $subdir,
        'url'     => $baseurl . $subdir,
        'subdir'  => $subdir,
        'basedir' => $basedir,
        'baseurl' => $baseurl,
        'error'   => false,
    );

}

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!