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:
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.
8 Responses to How To Disable Plugins On Home Page