Pin It

How To Disable Plugins On Home Page

Since this is a complicated topic I have made a video where I walk through it here (remember to set it to HD):

There are many instances where you might want to disable plugins from a certain page, particularly the home page. The fact of the matter is that not all plugins are necessary on all pages. What’s the harm in having them load? Well, for one thing it’s useless code that can slow down the load time, as most plugins come with their own stylesheets and javascript. Another problem you might run into is conflicts, for example, you might have some special function that operates specifically on your homepage, but it conflicts with the files that are loaded from a plugin, which focuses on comments (which has no business on a homepage). Thus, as you can see, while in many instances you’ll be “fine” to load plugins wherever, it’s generally good practice to limit plugins to pages where they are necessary.

I did some searching around to find some code that would accomplish this and frankly had a very, very difficult time. Certainly the question had been asked, but it was not being addressed properly. What I was able to find was some code here and some code there (mainly in old forum posts), that, together, were able to do the trick at least to some extent. I am not an expert on coding but I do believe the following is a good start, and it has certainly allowed me to disable a few pesky plugins from the home page where they are not needed.

Let’s start by introducing the functions that are going to be needed to accomplish this:

Necessary Functions:

What I’m showing here is a few wordpress functions which are used to essentially activate and deactiviate scripts(.js)/styles(.css). They work hand and hand, so if something is registered then it needs to be deregistered.

Now to show you what to do with them in a few simple steps:

  1. Identify which plugins you want to remove from the home page. One nice tool you can use is Pingdom. When you put in your website it shows you all of the scripts and stylesheets that are loading. You can look through and usually via the name identify which plugin they belong to. You should have a general idea of which plugins you want to remove just based on the general purpose and whether or not it is even necessary for the home page.
  2. Find the handle for the stylesheet/script by going to Plugins > Editor > Your Plugin (scroll down, top right) > .php file and search what is being registered or enqueued. If there are multiple .php files you might have to search through several of them, or try to identify, which one is the main .php file.
  3. Find out how it is being added. If it is being added via an action then you are going to need to remove it via remove_action() (see ffirst function). If it is being added via register or enqueue, then you are going to need to deregister it or dequeue it (see second function). Moreover, remember that .css need to use the style function and .js need to use the script function variant.
  4. Undo it in our function(s) via the counterpart function with the handle as the input. Here is the code below that you are going to want to paste into your custom functions file.
function remove_plugins() { 
 if (is_home()){ 
  remove_action('wp_head', 'dd_output_css_to_html'); 
  remove_action('wp_head', 'dd_get_thumbnails_for_fb'); 
 } 
} 
add_action('wp_head', 'remove_plugins', 1); 
add_action( 'wp_print_styles', 'my_deregister_styles', 100 ); 

function my_deregister_styles() { 
 if (is_home()){ wp_deregister_style( 'lightboxStyle' ); 
  //wp_dequeue_script( 'jquery-colorbox' ); 
  wp_dequeue_script( 'commentluv' ); 
  wp_dequeue_script( 'commentluv_script' ); 
 } 
}

Run Pingdom again and check to see that the specified .css and/or .js files are no longer active on your homepage.

If you enjoyed this article, join others and get free email updates!

8 Responses to How To Disable Plugins On Home Page

  1. I looked everywhere for code to be able to do this, and nothing worked (nor did any other site provide such a thorough explanation.

    A million thanks! Well done!

    Michelle February 26, 2013 at 11:06 PM Reply
    • So did I michelle, so did I…

      Then I decided to just WRITE the damn article myself – glad you liked it!

      Vicky February 27, 2013 at 2:01 AM Reply
    • so did I Michelle, so did I…

      So then I just decided to write the damn thing myself, glad you liked it – thanks!

      Vicky February 27, 2013 at 2:05 AM Reply
  2. Hi Dave

    I am not good with code, and I got a big problem. I am using CM Download Manager, but it cant load, because I am also using Rtmedia (also known as Buddypress Media). Is it possible that you could write a code to me, that disable Rtmedia on the page, where I have Cm Download Manager on. The page where I have CM Download Manager on, is called “Publish”

    I really hope you can help me. I would be very grateful.

    Thomas Sorensen August 25, 2013 at 2:20 PM Reply
    • Hey Thomas – unfortunately I am not really a coder either. I would recommend finding someone on elance.com to help you.

      Dave and Vicky August 25, 2013 at 2:43 PM Reply
    • Thomas the simplest is to use a Plugin called: “Plugin Organizer”
      Or you can write URL conditions in your thems functions.php

      Cyborg September 13, 2013 at 7:56 AM Reply
  3. Nice code!

    Do you know what it has to look like if I would like to disable NextGEN Gallery on the homepage?

    Hans September 19, 2013 at 10:16 AM Reply
    • Unfortunately for that one I don’t, but that doesn’t mean it can’t be done!

      Dave and Vicky September 19, 2013 at 3:40 PM Reply

Leave a Reply

Your email address will not be published.