• Hi
    I have a multisite and I would like to change the url’s of uploads so that instead of being
    /wp-content/uploads/sites/2/2021/10/image.png
    wp-content will be renamed and I’d like to get rid of the uploads and sites folders completely so it’s something like:
    /resources/29/2021/10/HUB84_LOGO.png

    It’s not the main site I need to do this on, only the subsites.
    Is there a way to do this?

    Thanks!

    • This topic was modified 3 years, 1 month ago by Jan Dembowski. Reason: Moved to Networking WordPress, this is not an Developing with WordPress topic
Viewing 5 replies - 1 through 5 (of 5 total)
  • Hi @lveale, moving the uploads folder in multisite is more complex than in regular single site WordPress. Take a look at this part of the docs around this:

    https://www.ads-software.com/support/article/multisite-network-administration/#uploaded-file-path

    Thread Starter lveale

    (@lveale)

    Thanks @mmaattiiaass sounds like this could be problematic…
    So my next question is, is it possible to mask the image urls in some way so that it doesn’t show the parts I want to remove on the front end in the address bar or when hovering over a link?

    Thanks!

    lsell

    (@lsell)

    It’s been a while since I set it up, so I may be forgetting some critical element, and I have my network configured so put all uploads in the same folder, regardless of site (and then have them further sorted by type and some other criteria) so it may not translate to your situation exactly, but I don’t recall replacing the wp-content/uploads/sites part of the upload path being all that difficult.

    I haven’t tested this exactly, but try something like:

    add_action('init', 'new_upload_filters');
    function new_upload_filters(){
    	if( !is_main_site() ) add_filter('upload_dir', 'new_upload_dir');
    }
    
    function new_upload_dir( $dirs ) { //set base upload folder
    	$site = get_current_blog_id();
    
    	$dirs['baseurl'] = network_site_url( '/resources' );
    	$dirs['basedir'] = ABSPATH . 'resources';
    	$dirs['path'] = $dirs['basedir'].$site;
    	$dirs['url'] = $dirs['baseurl'].$site;
    	return $dirs;
    }
    

    hope that helps!

    @lsell – Where did you put this code? Theme functions?

    @yourbusybee I did have it in theme functions originally, but ended up moving it into a plugin because a couple of my subsites use different themes and I didn’t want to have redundant code to maintain. Either way could work, depending on your setup/needs.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Change upload path for subsites in multisite’ is closed to new replies.