mirror of
https://gh.wpcy.net/https://github.com/mainwp/Code-Snippets-Functions.git
synced 2026-05-03 12:12:25 +08:00
25 lines
682 B
Text
25 lines
682 B
Text
add_filter( 'wpseo_sitemap_entry', 'wc_remove_hidden_products', 99, 3);
|
|
function wc_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', 'wc_noindex_hidden_products', 10, 2);
|
|
function wc_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;
|
|
}
|