Skip to content

Instantly share code, notes, and snippets.

@cjj25
Last active September 9, 2022 11:39
Show Gist options
  • Save cjj25/b1521aa2b2ab4f3067c1e6ef8ad1dbed to your computer and use it in GitHub Desktop.
Save cjj25/b1521aa2b2ab4f3067c1e6ef8ad1dbed to your computer and use it in GitHub Desktop.
Prevent Yoast SEO from adding indexes to WooCommerce order data for a performance increase at checkout
<?php
# Place this code in your theme's functions.php
# Tested with WooCommerce 5.3.0 and Yoast SEO 16.4
if(function_exists('YoastSEO')) {
# Hook directly at the start of the init tree (important)
add_action('init', "maybe_remove_yoast_seo_module", 0);
function maybe_remove_yoast_seo_module()
{
$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;
$yoast = YoastSEO()->classes->container->get(Yoast\WP\SEO\Loader::class);
remove_action('init', [$yoast, 'load_integrations']);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment