Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

CDN in WP-ADMIN WordPress


I am using WP-Super-Cache plugin and it comes with a CDN module.
I noticed that the CDN module does not rewrite URLs when in wp-admin, but works fine in public pages.

Can someone provide a modification to ossdl-cdn.php so that it will also rewrite the URLs to CDN when logged in to wp-admin?


Answers (3)


Dbranes answers:

Hi Raymond

Good advices from others here, but you can try to change the <em>base_url</em> for the default scripts and styles with the following:

add_action( 'admin_init', 'wpq_admin_init' );

function wpq_admin_init(){

global $wp_scripts, $wp_styles;

$wp_styles->base_url = '';
$wp_scripts->base_url = '';

where you have:


in your <em>wp-config.php</em> file.


You can also try the <em>script_loader_src</em> filter:

is_admin() && add_filter( 'script_loader_src', 'wpq_script_loader_src' );
function wpq_script_loader_src( $src ){
$src = str_ireplace( $old_domain, $new_domain , $src );
return $src;

and similarly for the <em>style_loader_src </em>filter.

raymond comments:

Thanks Birgir, that worked!

Well the reason why I wanted to offload all the static files to CDN is because I've recently moved to an all HTTPS and I don't want to burden my server.

There seems to be a few more files not loading from CDN after implementation.


From plugins:

Dbranes comments:

ok, see the updated answer.

raymond comments:

Do I need to change the "$old_domain, $new_domain" to reflect on my original domain and CDN?

Dbranes comments:


raymond comments:

Works out really well.

It seems that there are also static files being loaded from wp-admin folder.
Some files such as:


Would be great if they can be loaded from CDN as well. Thanks!


zebra webdesigns answers:

Hello Raymond

Your question is little confusing.
Why you need to rewrite the URL inside wordpress admin.

raymond comments:

I only need to "rewrite static files" (such as .JS and .CSS) from wp-admin to CDN.

zebra webdesigns comments:

Raymond Can you add me in skype
Skype ID: bhuvan530531


Francisco Javier Carazo Gil answers:


A CDN inside back-end has no much sense, the user is you and the updates can be problematic. Maybe many users access to dashboard (in that case it can be useful) but MySQL queries time in back-end take much time so it wouldn't be a very good solution.

raymond comments:

I have thought about the consequences weighing the pros and cons, but I would still very much like to cache the static files loaded in wp-admin. Thank you.

Francisco Javier Carazo Gil comments:


Think that the browsers will cache all this info: JS and CSS, until you don't change version in wp_enqueues... so another idea to provide agains it.