Skip to content

Instantly share code, notes, and snippets.

@cjj25
Created June 4, 2021 08:48
Show Gist options
  • Save cjj25/fe9113df8961ad035ef665b3bfe2e7d3 to your computer and use it in GitHub Desktop.
Save cjj25/fe9113df8961ad035ef665b3bfe2e7d3 to your computer and use it in GitHub Desktop.
Completely Disable Yoast SEO at WooCommerce checkout using mu-plugin
<?php
# Place this file in the ROOT of wp-content/mu-plugins
# If the folder doesn't exist, create it.
add_filter('option_active_plugins', 'custom_disable_plugins_1');
function custom_disable_plugins_1($plugins)
{
$remove_plugin = false;
$plugin_to_disable = "wordpress-seo/wp-seo.php";
# Never remove from admin or customize view
if (is_admin() || is_customize_preview() || defined("WP_CLI")) return $plugins;
# Don't load the plugin on these routes
$do_not_load_yoast_routes = [
'/checkout/',
'/basket/',
'/?wc-ajax=update_order_review',
'/?wc-ajax=add_to_cart',
'/?wc-ajax=checkout',
'/?wc-ajax=get_refreshed_fragments'
];
foreach ($do_not_load_yoast_routes as $URI) {
if (strpos($_SERVER['REQUEST_URI'], $URI) === false) continue;
$remove_plugin = true;
break;
}
if (!$remove_plugin) {
return $plugins;
}
if (($search = array_search($plugin_to_disable, $plugins)) !== false) {
unset($plugins[$search]);
}
return $plugins;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment