Change template_directory to use a CDN path

Posted on 16th September, 2015 53 Comments

So you’ve created your theme and you would like to switch to using a CDN for your scripts and CSS…

Add this to your functions.php and replace the YOUR-SITE with the urls of the website and the CDN.

add_filter( 'template_directory_uri', function( $template_dir_uri ){
return str_replace( 'http://www.YOUR-SITE.co.uk/', '//cdn.YOUR-SITE.co.uk/', $template_dir_uri );
});

Comments

To preserve code added to a comment you can wrap your code in short tags
by using [square brackets]:

  1. PHP use - [php] <?php code here ?> [/php]
  2. CSS use - [css] #code-here {} [/css]
  3. HTML use - [html] <div> code here </div> [/html]
  4. JS use - [js] $(".codeHere") [/js]

JamesVen

20th, Oct, 20

be a outstrip urgently fitted the next legit and Mawkishness [url=https://ciamedusa.com/]cialis from canada[/url] Owekek qfiwwt cialis effective buying cialis online safely

JamesVen

21st, Oct, 20

propagation: To delays the device go along an allergist of. [url=https://ciamedusa.com/#]generic cialis india[/url] and misinterpreting them its compromises to position statement

카지노사이트

07th, Jan, 21

Thanks again for stopping by, Solanski. Hope you’re having a great weekend.
You know, “trying not to sound like an idiot” is a pretty decent approach to commenting. If only every commenter took that approach! Haha.
카지노사이트

hey

13th, Jan, 21

Taxi moto line
128 Rue la Boétie
75008 Paris
+33 6 51 612 712  

Taxi moto paris

Pretty! This was an incredibly wonderful article.
Thank you for providing these details.

vreyrolinomit

17th, Jan, 21

Hmm it appears like your website ate my first comment (it was super long) so I guess I’ll just sum it up what I submitted and say, I’m thoroughly enjoying your blog. I as well am an aspiring blog writer but I’m still new to everything. Do you have any recommendations for beginner blog writers? I’d certainly appreciate it.

Lcxeloks

21st, Jan, 21

viagracanada viagra canada pfizer viagra [url=http://genqpviag.com/]where can i buy viagra in ireland[/url] ’

KbbtBoth

24th, Jan, 21

cheap. generic cialisis Lotensin best price for cialis 20 mg [url=https://xz-pharmacyonline.com]canadian drugstore[/url] ’

froleprotrem

28th, Jan, 21

I have been checking out some of your posts and i can claim clever stuff. I will surely bookmark your site.

Leave a Comment

To preserve code added to a comment you can wrap your code in short tags
by using [square brackets]:

  1. PHP use - [php] <?php code here ?> [/php]
  2. CSS use - [css] #code-here {} [/css]
  3. HTML use - [html] <div> code here </div> [/html]
  4. JS use - [js] $(".codeHere") [/js]