unlist-posts
unlist-posts copied to clipboard
Hide unlisted posts from Yoast SEO sitemap
I just came across this looking for a solution, and decided to share my own.
I put the following in my theme's functions.php:
// Hide unlisted posts from sitemap.xml in Yeost SEO
// Add this to your theme's functions.php
// See: https://kb.yoast.com/kb/sitemap-shows-excluded-posts-pages/
add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', function () {
$hidden_posts = get_option( 'unlist_posts', array() );
return $hidden_posts;
} );
Hope that helps others :)
I just came across this looking for a solution, and decided to share my own.
I put the following in my theme's functions.php:
// Hide unlisted posts from sitemap.xml in Yeost SEO // Add this to your theme's functions.php // See: https://kb.yoast.com/kb/sitemap-shows-excluded-posts-pages/ add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', function () { $hidden_posts = get_option( 'unlist_posts', array() ); return $hidden_posts; } );
Hope that helps others :)
Works, thank you
If you use AIOSEO this will do the equivalent.
add_filter( 'aioseo_sitemap_exclude_posts', 'aioseo_sitemap_filter_excluded_posts', 10, 2);
function aioseo_sitemap_filter_excluded_posts( $ids, $type ) {
$hidden_posts = get_option( 'unlist_posts', array() );
return $hidden_posts;
}