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

Leave a Reply

Your email address will not be published.