I'm using multisite and want all my scripts to point to the same URL so they are optimized as well as they can be. Currently I have:



But they both reference the same file. I'd like them to be both something like:


That way it would save people having to download the same file again even though they already have it cached locally. This question is the same question but the solution isn't up to date. Does anyone have any ideas of code or any plugins that might help solve ?


  • Apart from the suggestions to the other question, why not use plugins to include your code? That way all your sites reference the singular plugin url. Commented Apr 9, 2014 at 23:48
  • oh good idea, like having an include_scripts plugin. Sorry I had forgotton I'd asked this question actually solved it in the week, I'll post what I did when I'm back in work. I think there's a filter that you can use to pull out the main url and then replace it with the first blog in multisite (or any blog). But your solution would solve it all the same in a different way. Maybe even a performance gain on your one. Cheers
    – danbrown
    Commented Apr 10, 2014 at 8:04

1 Answer 1


Hi this is what I did to solve it:

add_filter( 'script_loader_src', 'change_src' );
add_filter( 'style_loader_src', 'change_src' );

function change_src( $url )
    if( is_admin() ) return $url; // Don't filter admin area
    return str_replace( site_url(), 'www.mysite.com/mydefaultnetworksite', $url );

I'm using both those filters because I want it to apply to script and stylesheet urls. The function just looks for the site url, rips it out and replaces it with a hardcoded version of the url I want all the sites scripts / stylesheets to point to.

I opted for the first site in the multisite, but it could be any :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.