63 responses to “How to disable scripts and styles”

  1. Ben

    The other problem comes from plugin that, as you said in the begining of the article, don’t use wp_enqueue. We can get rid of those by removing the wp_head filter the plugin uses to append the script/style.

    It would be so good if every plugins were giving you the chance to say where they are allowed to include styles and scripts. Most of them just include on every page, regardless of if the script is used or not…

  2. links for 2009-08-06 | Links | WereWP

    [...] How to disable scripts and styles A great tutorial by Justin Tadlock. You will learn how to integrate plugins in a clean way with your theme, in order to load pages faster and in a better way. (tags: wordpress tutorial plugin style css javascript) [...]

  3. J Mehmett

    Short, descriptive and sweet tip. Thanks for sharing this with us.

    I figured out that, the script can be registered, only, when needed:

    add_action( 'wp_print_scripts', 'my_deregister_javascript', 100 );
    
    function my_deregister_javascript() {
       if ( !is_page('Contact') ) {
    	wp_deregister_script( 'contact-form-7' );
         }
    }

    So it will load that script only on Contact page…

  4. Banago

    Really useful technique. I have been looking for something like this.

    The solution that J Mehmett added to the script is very nice too.

    Great job.

  5. takayukister

    Hi Justin! Thank you for nice articles every time :)

    To Contact Form 7 users, you can also use WPCF7_LOAD_JS constant to control JavaScript loading.

    http://ideasilo.wordpress.com/2009/05/31/contact-form-7-1-10/

    Takayuki Miyoshi (author of Contact Form 7)

  6. brainsolid

    Hi, Justin!
    Sorry for offtopic)
    Your widget “WordPress-o-Sphere” in sidebar — is this just text widget or some kind of plugin?

  7. Gaby

    Oh this is a wonderful tip :D I have many plugins so I’ve been thinking of trying to reduce the load they put on the site and this could really help. Thank you!

  8. Keith Purkiss (Alex Jeffreys Student)

    Thanks Justin,

    That’s a good point and it’s a good idea to tidy it all up into one style sheet.
    I’m trying to keep my plug-ins to a minimum and havent looked at this yet, but one link widget I had uses a remote file which is also going to slow it down. Possible I could copy that file onto my server although that would mean updating it regularly.

    Thanks

    Keith

  9. WordPress trick: Disable plugin stylesheet

    [...] to Justin Tadlock for this great recipe! If you enjoyed this article, please consider sharing it! [...]

  10. Joe Somebody

    This couldn’t have come at a better time. One thing that has always annoyed me about Contact Form 7 was the fact that it loaded what was only needed on the contact page onto every single page of the site. I now have exactly what I need to create cleaner and meaner WordPress based sites.

  11. Simon Wilby

    Great! Timely script for me. Just checking out my scripts and found out I need to disable some styles of my page.

  12. Gilbert

    Hi Justin,

    Love your articles in general.
    Just a question out of the scope of this article: how do you setup the “notify me of followup comments via e-mail” as you are doing below?

    Are you using “http://txfx.net/code/wordpress/subscribe-to-comments/”?

  13. V.C

    It’s really useful.
    But what about the others?
    How could I disable them :-<

  14. WordPress Weekend Resources - August 14, 2009 | Theme Lab

    [...] How to disable scripts and styles – In this post, Justin Tadlock goes over how to disable scripts and styles added to your WordPress sites by plugins. This has a number of uses, for example if you don’t want the Contact Form 7 stylesheet to load on other pages besides your “Contact” page. [...]

  15. Wordpress Blog Services - WordPress Weekend Resources - August 14, 2009

    [...] How to disable scripts and styles – In this post, Justin Tadlock goes over how to disable scripts and styles added to your WordPress sites by plugins. This has a number of uses, for example if you don’t want the Contact Form 7 stylesheet to load on other pages besides your “Contact” page. [...]

  16. Eduard Seifert

    Hi Justin, thank for this really handy tip. Now i know how to disable the CSS from the Cleaner Gallery Plugin without commentig out every time you update your plugin.

    /**
     * Remove CSS Styles added by Plugins
     * @note use plugin directory name
     * @see  http://justintadlock.com/archives/2009/08/06/how-to-disable-scripts-and-styles
     */
    function my_deregister_styles() {
    	wp_deregister_style( 'cleaner-gallery' );
    }
    my_deregister_styles();

    Thank you very much.

  17. Como desativar scripts e estilos no wordpress | Ajuda Wordpress em Português

    [...] WordPress dispõe de um sistema próprio que permite anular estes scripts e [...]

  18. Como desactivar scripts y estilos | Zona-WordPress

    [...] WordPress dispone de un sistema propio que permite anular estos scripts y [...]

  19. GB Pics

    Short, descriptive and sweet tip.

  20. החלקה יפנית

    That wasvery usefull to all of us.
    The good thing in WP is that it’s very friendly, has a lot of plugins and a lot of knowledge such as Justin’s. But it’s quiet confusing for beginners.
    I moved from shared blogging system towards WP.
    Can you refer for the beginners any simple website, beside your most important post ?

  21. Pen Whitening

    Thanks for simplifying this otherwise complex process so even a WP newbie like me can tackle this performance optimization. However, I will leave the file merge to an expert.

  22. Jonas8

    Very useful tip. When a project tends to evolve, a plethora of plugins tend to follow. Advice like this can make all the difference. Thanks!

  23. Daniel

    This is a really great tutorial. One of my websites has become insanely slow, and I followed these instructions and it helped a lot! Thanks mate!

  24. 10 WordPress ‘HOW-TO’ to Give it the Quality it Deserves

    [...] this tutorial Justin Tadlock describes a smart solution to disable scripts and styles of your plugins by looking [...]

  25. 10 WordPress ‘HOW-TO’ to Give Your Blog the Quality it Deserves | Webmaster Tips

    [...] this tutorial Justin Tadlock describes a smart solution to disable scripts and styles of your plugins by looking [...]

  26. Teresa White

    Thanks for great tips. I followed your instructions, changed theme and my blog loads 5 times faster

  27. 10 WordPress ‘HOW-TO’ to Give Your Blog the Quality it Deserves | huibit05.com

    [...] this tutorial Justin Tadlock describes a smart solution to disable scripts and styles of your plugins by looking [...]

  28. 10 WordPress ‘HOW-TO’ to Give Your Blog the Quality it Deserves | SeanBurdick

    [...] this tutorial Justin Tadlock describes a smart solution to disable scripts and styles of your plugins by looking [...]

  29. Paula

    Some of the blog I frequent on a regular basis could do with reading this article. I’ll discretely pass this post onto some of them. Thanks

  30. Bookmarks for 21.08.2009 through 26.08.2009 - mafflog

    [...] How to disable scripts and styles – [...]

  31. WordPress trick: Disable plugin stylesheet « Test Blog

    [...] to Justin Tadlock for this great [...]

  32. Chris

    this is a useful techniques.thanks for a nice article i might be thinking to change my theme and this will be a very useful guide for me.

  33. David

    Tips on making this work better

    I’d add one more – use a plugin like Headspace2, it enables you to load scripts, css, or just raw head data on a post by post basis, after you’ve stopped them loading globally. So I do that with wp-polls, so the poll css is not on every page when I only need it on an occasional post.

  34. Kim

    Thanks for this Justin. I have several plugins that I have customized the styles for and now I don’t have to worry about editing their respective stylesheets every time the plugin is updated.

  35. Judith

    At the beginning I also tried out every plugin and widget available. But it really slowed down my whole page. Also it sometimes looks unprofessional if you have to many widgets and plugins. But thank you Justin for providing us with a script. That way you don’t have to uninstall everything – what I always did until now.

  36. Aktuelle Links (gespeichert vom 04.09.2009 bis zum 05.09.2009) « Der Webanhalter

    [...] WordPress: How to disable scripts and styles (from Plugins) Many plugins and themes add JavaScript and CSS files to your site. While this alone isn’t necessarily a bad thing, using several plugins that do this can bog down your site with loads of requests for these files. [...]

  37. jonty

    excellent as always !
    I’m goonna check the Disabling javascript, I have to fix something around that using that snipe..

  38. 10 секретов и примочек для wordpress | cooledit

    [...] уроке Джастина Тэдлока описывается довольно таки хорошее [...]

  39. Stefan

    Please pardon the clueless here but: “deregister as many stylesheets as you need”
    I can get one stylesheet to “de-regester” but I can not figure out the syntax to de-regester 2 stylesheets without breaking functions.php.
    I guess I’m looking for an example with 2 de-regestered stylesheets.
    Thanks, S

  40. Kim

    @Stefan: Did you try listing each handle as follows:

    function my_deregister_styles() {
    	wp_deregister_style( 'wp-pagenavi', 'cleaner-gallery' );
    }
  41. Stefan

    @Kim: Yes i did, whatever handle is in the second spot (cleaner-gallery in your example) is still being requested when I look in firebug at the css requests for that page.
    I thought perhaps I was missing a space or something but no joy. I even swapped around the handle’s and only the first one is no longer requested.
    I am trying to de-regester wp-postratings, theme-my-profile and theme-my-login, anyone of these in the first position gets de-regestered second one is still requested.
    It must be my syntax though I copied the examples………hmmmm.

  42. Daniel Suffolk

    A great read thank you, I have only just started playing around with wordpress and your tips have come in handy,

  43. Dave

    @Stefan, did you find a solution to de-registering more than one script? I can’t figure it out either.

  44. Dave

    Of course, as soon as I ask the question, I figure it out. Very simple:

    function my_deregister_styles() {
    	wp_deregister_style( 'wp-pagenavi' );
    	wp_deregister_style( 'contact-form-7' );
    }
  45. Jack

    I can put in the header instead of the functions.php?

    add_action( 'wp_print_scripts', 'my_deregister_javascript', 100 );
    
    function my_deregister_javascript() {
    	wp_deregister_script( 'contact-form-7' );
    }

    Or put the function in functions.php and add_action the header?

  46. Kim

    @Jack: You would add all of that code to your functions.php file, and it will remove the javascript from the header automatically. You don’t need to edit your header.php file at all.

  47. Stjepan Tafra

    Is it possible, using this method, to prevent NextGen gallery from inserting the version number into tags?

  48. 12 Lesser Known But Useful WordPress Hacks

    [...] Source: How to Disable Scripts and Styles – Justin Tadlock [...]

  49. Wordpress: Performance optimieren | bertdesign.de

    [...] man über ein paar Zei­len Code in der functions.php unter­bin­den. Wie das funk­tio­niert, erklärt Jus­tin Tad­lock. Für diese Maß­nahme ist eini­ges an Hand­ar­beit inklu­sive Code-Analyse der Plugins [...]

  50. How to Disable Scripts And Styles : Wordpress Hack

    [...] Credit To : How to disable scripts and styles [...]

  51. Darrin

    Ooh excellent post. I didn’t know that this was possible. I was always afraid to mess with the plugins for fear of breaking it altogether. Time to go mess with my site and hope I don’t break it to bad.

  52. Disabling Scripts and CSS styles in WordPress | Netvivs

    [...] I found this interested article from Justin Tadlock that realized me a quick and elegant way to disable scripts or styles enqueued [...]

  53. Ryan Isra

    Nice post, for those who weren’t advanced in programming, especially web programming.

  54. Devin

    Thanks for posting this Justin. I just added the WP Navi deregister to my list of useful Thematic filters- even though it’s only sorta related. Too useful to leave off though: http://wordpresstheming.com/2009/10/useful-thematic-filters/.

  55. Benjamin

    This worked great: but is there a way to enable it only on certain templates instead of the exact page? For instance if I want a certain script to be allowed on single.php pages?

    Thanks in advance! I’m still wrapping my head around much of this code!

  56. Thomas Carter

    @Ben for sure i’ve just done this, based on J Mehmett’s great comment (the 2nd comment)

    Based on your example:

    if(!is_single()){
    wp_deregister_script(‘the-script’);
    }

    So if the page is not single.php the script will be de-registered!

  57. Funktionen, Javascripte und CSS Styles aus wp_head entfernen « design & programmierung

    [...] Eine ausführlichere Beschreibung zu diesem Thema liefert: justintadlock.com/archives/2009/08/06/how-to-disable-scripts-and-styles [...]

  58. 20+ Tips Lengkap Optimasi WordPress

    [...] dan rumit, karena harus mengedit file plugin yang dipakai. Informasi lengkap bisa dibaca di blog Justin Tadlock, White Shadow, dan Coen [...]

  59. How to load Javascript on specific pages in Wordpress – Web Design / Development | FLDtrace

    [...] Tadlock on his blog, offers a more in depth tutorial regarding this [...]

  60. Increasing The Speed Of Your WordPress Blog | DevWebPro

    [...] is the snippet of code that got me started, from Justin Tadlock’s blog post; it will disable Contact Form 7’s loading [...]

Leave a Reply

By submitting a comment here you grant this site a perpetual license to reproduce your words and name/Web site in attribution.

Please use your real name or a pseudonym (e.g., pen name, alias, nom de plume) when commenting. If you add your site name, company name, or something completely random, I'll likely change it to whatever I want.