I’m using Yoast SEO plugin and I'm trying to exclude posts manually from posts XML sitemap using 'wpseo_sitemap_entry' filter but so far have no luck.
This is my current code:
function sitemap_exclude_post( $url, $type, $post) { if($post->ID == 6298 ) { return false; } return $url;}add_filter( 'wpseo_sitemap_entry', 'sitemap_exclude_post', 1, 3 );
Any suggestions will be much appreciated?
Note: I know it can be done via Yoast plugin's backend by manually entering post IDs but I need to do it via filters. The above code is going to be further changed later to automatically obtain Post IDs of posts(single.php) from a category in wordpress.