Plugins are essential for increasing the functionality of a WordPress website. However, you shouldn’t go overboard installing plugins, as they can slow down page loading and seriously affect your site’s performance.
The moment you install a plugin on your WordPress site, it loads not only on the page you’re using it on, but on all pages, even if you’re not actively using it. That means more code to run, and more server processing time. And this can be a problem because we should always try to achieve the best possible performance on our website. After all, loading speed is one of the aspects Google takes into account when ranking a website on Google.
If you want to try to improve the performance of your WordPress site as much as possible, it’s important to learn a few tricks. If you have 10 minutes, stick with this guide because you’ll learn how to disable a WordPress plugin on certain pages. The goal is to have the plugins you want without compromising your website’s performance.
Guide | How to deactivate a WordPress plugin on specific pages step by step
Every time a user requests a page from the server, WordPress executes the necessary code (and that includes each plugin separately).
Do we really want the contact form plugin to run on a page without a contact form? No. Not only are we not interested, but we should try to fix this to improve the website’s performance.
For example, Contact Form 7 —one of the best contact form plugins in WordPress— runs on every page even if there isn’t a form, if only to determine that there isn’t one on that page. Not only that, in this particular case, when CF7 runs, some completely unnecessary CSS and JS files are loaded.
To improve the site’s performance we want the plugin code to run only on the pages we’re interested in. Taking the previous contact form example, we will want it to load only on pages where the form is displayed, such as the Contact, Returns, and WordPress backend pages.
To do this, we can’t touch the functions.php file. Instead, we must create a mu-plugin.
A mu-plugin (Must-Use plugin) in WordPress is a PHP file placed in the wp-content/mu-plugins directory that loads automatically on every page load without needing activation. To create one, simply create the mu-plugins folder if it doesn’t exist, add a PHP file (e.g., my-plugin.php) with a standard plugin header and your custom code, and WordPress will load it automatically.
So, copy and paste the following code as a mu-plugin, and you’re done.
<?php
add_filter( 'option_active_plugins', 'disable_plugin_except_pages' );
function disable_plugin_except_pages( $plugins ) {
if ( is_admin() ) {
return $plugins;
}
$allowed_pages = [ '/contacto/', '/devoluciones/' ]; // Pages where the plugin should be active
if ( ! in_array( $_SERVER['REQUEST_URI'], $allowed_pages ) ) {
$key = array_search( 'contact-form-7/wp-contact-form-7.php', $plugins );
if ( false !== $key ) {
unset( $plugins[$key] );
}
}
return $plugins;
}
Remember to save your changes.
Now, this code forces the contact form plugin to load only the Contact and Returns URLs, as well as the entire WordPress backend. If that’s what you want, copy and paste the code directly.
If you want to add more pages, you can do so from the following line of code: $allowed_pages = [ '/contact/', '/returns/' ]; This way, it will only load on the pages you specify.
If you want to do the opposite, so that the pages you indicate are where the plugin in question does not load, all you have to do is remove the exclamation mark from the line if ( ! in_array( $_SERVER['REQUEST_URI'], $allowed_pages ) ) {, like this:
<?php
add_filter( 'option_active_plugins', 'disable_plugin_except_pages' );
function disable_plugin_except_pages( $plugins ) {
if ( is_admin() ) {
return $plugins;
}
$allowed_pages = [ '/contacto/', '/devoluciones/' ]; // Pages where the plugin should be active
if ( in_array( $_SERVER['REQUEST_URI'], $allowed_pages ) ) {
$key = array_search( 'contact-form-7/wp-contact-form-7.php', $plugins );
if ( false !== $key ) {
unset( $plugins[$key] );
}
}
return $plugins;
}
Also, remember that you can customize the code for each plugin. The example we’re sharing is for the Contact Form 7 plugin, but you can do it for any plugin you want. You’ll simply need to change this line: $key = array_search( 'contact-form-7/wp-contact-form-7.php', $plugins );. In this case, contact-form-7 is the plugin folder and wp-contact-form-7.php is the main plugin file.
Why is it important to disable plugins on pages where they are not used?
It’s essential to do this for performance reasons. Keep in mind that most people don’t do this because they’re completely unaware of it, but it’s essential to try to achieve the best possible loading speed on your site. The faster it loads, the better for Google and also for the end user, as you’ll offer a better user experience and increase your business’s sales.
In short, the advantages of this trick are:
- Faster loading speed: An aspect that can improve your search engine rankings.
- Better user experience: A slow page can increase the bounce rate, while a page that loads faster can help boost your business’s sales.
Considering these advantages, it’s worth spending a little time making these adjustments.
And what if I don’t know how to do this?
If you have any questions, remember we can do it for you. The speed of your website is one of the most important aspects for your business to succeed. If you prefer to delegate, we’ll take care of reviewing your website and improve everything as much as possible so it loads lightning-fast!



