Product pages can be excluded from the XML sitemap by following these steps: Sitemap shows excluded posts / pages Additionally, you can use the filter wpseo_sitemap_entry to exclude a page from the sitemap.
If the options above are not enough for your purposes, we’d kindy ask you to create a new feature request for our developers at https://github.com/Yoast/wordpress-seo/issues/new. You will need an account to create one.
Can you give me an example of the use of wpseo_sitemap_entry?
If have tried this:
add_filter( 'wpseo_sitemap_entry', 'sitemap_exclude_product, 10, 3 );
function sitemap_exclude_product( $url, $type, $post ) {
if($post->ID===25166){
return '';
}
return $url;
}
But product still shows up in sitemap.xml…..
Hi,
We can’t offer support on custom code (needed to change (core) features of our plugin). Since we don’t want to take the risk that we break your website by suggesting incorrect or incomplete code, we cannot advise you on how to make such changes. Maybe someone watching these forums can assist you further, but if your topic is inactive for 7 days, we’ll mark it as resolved to keep the overview.
Thank you for your understanding.
But, wpseo_sitemap_entry is not custom code… its part of the plugin….
I’m just asking, if I’m using it in the correct way to exclude postid 25166
Hi,
We understand the filter is part of the Yoast plugin but we are unable to provide advice or code on how to implement the filter in the manner in which was described. We suggest continued experimentation, waiting to see if someone watching the forums can provide advice, or hiring a developer from out recommended list here: https://yoast.com/hire-us/website-review/implementation-partners/
Ok, thanks for explaining.
You can close this… above is indeed the way to go.. but I must force rebuild of xml, by turning xml off and on again. Only then will you see changes right away.