Versteckte WooCommerce-Produkte in Yoast auf noindex setzen
· von Daniel
WooCommerce-Produkte mit der Sichtbarkeit „Versteckt“ (aus dem Katalog ausgeschlossen) werden von Yoast SEO trotzdem indexiert. Um sie aus den automatisch erzeugten Sitemaps zu entfernen und auf „noindex, nofollow“ zu setzen, fügen Sie die folgenden 2 Funktionen in Ihre functions.php ein
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;
}