Start a project
WooCommerce

No index hidden WooCommerce products from Yoast

· by Daniel

WooCommerce Products with the visibility status hidden (excluded from catalog) are still indexed by the Yoast SEO tool. TO remove them from the automatically generated Sitemaps and set the index status to “noindex, nofollow” add the following 2 functions to your functions.php

add_filter( 'wpseo_sitemap_entry', 'we_remove_hidden_products', 99, 3);
function we_remove_hidden_products($url, $type, $post) {
	if($post->post_type == 'product' && is_object_in_term( $post->ID, 'product_visibility', 'exclude-from-catalog')){
		return '';
	}
	return $url;
}
add_filter('wpseo_robots', 'we_noindex_hidden_products', 10, 2);
function we_noindex_hidden_products($robots, $indexable) {
	if(!isset($indexable->model)) {
		return $robots;
	}
	if(!isset($indexable->model->object_id)) {
		return $robots;
	}
	if(is_object_in_term( $indexable->model->object_id, 'product_visibility', 'exclude-from-catalog')){
		$robots = 'noindex, nofollow';
	}
	return $robots;
}

Questions & answers (2)

  1. StasOctober 11, 2023

    Hello!
    What is the correct way to rewrite a function for use with $meta_query?
    For example, to use “_stock_status” instead of “product_visibility”

  2. GerardoAugust 10, 2023

    Hello Daniel,
    Thanks for posting this! I was wondering if this functions will work with any of the SEO plugins out there, or just Yoast?

    Thank you,
    Gerardo

More articles

All articles →
WooCommerceOctober 29, 2026 EmpCo Directive: What Online Shops Must Know About Green Claims Since 27 September 2026 “Sustainable”, “climate-neutral shipping”, “eco-friendly packaging”: claims like these appear in many online shops – in product texts, banners, badges in the footer or in carbon of… WooCommerceDecember 22, 2023 Prevent WP Rocket from Caching Filtered WooCommerce pages When using WP Rocket with preloading in combination with a filter plugin like Filter Everything pro, then your database AND cache folder can explode. We had a site with only around… WooCommerceApril 20, 2022 How to Reactivate old WooCommerce PayPal Standard Gateway WooCommerce has replaced the old PayPal Standard Payment Gateway since version 5.5.

Let's increase your online sales.

Tell us about your shop or website. A developer replies, not a sales team.

★ 4.85/5 from 800+ ratings · Envato Elite Author · Made in Germany