Hello Deflime,
Thanks for reaching out about excluding multiple post types from the sitemap. This should be possible, with something like the code below:
function sitemap_exclude_post_type( $excluded, $post_type ) {
$excludedPostTypes = array("product", "post");
if (in_array($post_type, $excludedPostTypes))
return true;
return false;
}
add_filter( 'wpseo_sitemap_exclude_post_type', 'sitemap_exclude_post_type', 10, 2 );
However, we recommend testing this on a staging site to see if it meets your expectations before using on a live site.
That works! Thank you so much Maybellyne.
-
This reply was modified 4 years, 6 months ago by
deflime.
I am having a problem right now. I also used this line of code
function sitemap_exclude_post_type( $value, $post_type ) {
if ( $post_type == 'listings' ) {
return true;
}
}
However, I tried to check the post type so that I would know if it’s working by including var_dump in it. As shown below:
function sitemap_exclude_post_type( $value, $post_type ) {
if ( $post_type == 'listings' ) {
return true;
var_dump($post_type);
}
}
Suddenly, it shows list of post types so I knew it worked somehow. Once I removed the var_dump, it wouldn’t go out. Please help.