0

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:

http://www.site.com/news/wp-content/themes/js/bxslider.js

http://www.site.com/events/wp-content/themes/js/bxslider.js

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

http://www.site.com/wp-content/themes/js/bxslider.js

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 ?

Thanks

  • 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. – Innate Apr 9 '14 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 Apr 10 '14 at 8:04
0

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 :)

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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