Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wp-seopress/2bffad6b60d5d282f07334a9b77f37c0 to your computer and use it in GitHub Desktop.
Save wp-seopress/2bffad6b60d5d282f07334a9b77f37c0 to your computer and use it in GitHub Desktop.
Set hidden WooCommerce products meta robots to noindex
add_filter('seopress_titles_robots_attrs', 'sp_titles_robots_attrs');
function sp_titles_robots_attrs($attrs)
{
if (function_exists('wc_get_product')) {
$product = wc_get_product(get_the_ID());
if (isset($product)) {
$product_visibility = $product->get_catalog_visibility();
//Check product visibility
if ($product_visibility ==='hidden') {
unset($attrs);
$attrs = ['noindex,follow'];
}
}
}
return $attrs;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment