Im trying to disable a plugin on a Wordpress frontpage, to make it a bit lighter. I only want it disabled when the front page is displayed.
I got this working code where I put in wp-content/mu-plugins/ It disables one plugin on all pages except a specified /subpage/ This is great, but it's not exactly what I am after.
How can I change this code to disable a plugin only when viewing the front page ?
Here is the code :
add_filter( 'option_active_plugins', 'lg_disable_plugin' );
function lg_disable_plugin($plugins){
if(strpos($_SERVER['REQUEST_URI'], '/subpage/') === FALSE AND strpos($_SERVER['REQUEST_URI'], '/wp-admin/') === FALSE) {
$key = array_search( 'was-this-helpful-pro/was-this-helpful-pro.php' , $plugins );
if ( false !== $key ) {
unset( $plugins[$key] );
}
}
return $plugins;
}
I also found another code which works for other pages.... But its the same story , I cannot figure out how to make it work for the frontpage, only works on subpages**
$listener_term = '/subpage/';
$current_url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . '';
// listener for the thin load
if ( strstr( $current_url, $listener_term ) ) {
add_filter( 'option_active_plugins', 'api_request_disable_plugin' );
}
function api_request_disable_plugin( $plugins ) {
$plugins_not_needed = array(
'backupwordpress/backupwordpress.php',
'wordfence/wordfence.php',
'contact-form-7-to-database-extension/contact-form-7-db.php',
'contact-form-7/wp-contact-form-7.php',
'wp-piwik/wp-piwik.php',
'simple-responsive-slider/simple-responsive-slider.php',
'google-sitemap-plugin/google-sitemap-plugin.php',
'category-page-icons/menu-compouser.php',
'easy-fancybox/easy-fancybox.php',
'business-owner-switch/business-owner-switch.php',
'wordpress-seo/wp-seo.php'
);
foreach ( $plugins_not_needed as $plugin ) {
$key = array_search( $plugin, $plugins );
if ( false !== $key ) {
unset( $plugins[ $key ] );
}
}
return $plugins;
}
Any ideas?
I guess I should mention that:
- The first example will disable the plugin on all pages except for /subpage/
- The second code will disable all the listed plugins on /subpage/
Neither of them work for frontpage/homepage, no matter what I try.