unlist-posts icon indicating copy to clipboard operation
unlist-posts copied to clipboard

Hide unlisted posts from Yoast SEO sitemap

Open Nikschavan opened this issue 6 years ago • 3 comments

Nikschavan avatar Sep 08 '18 11:09 Nikschavan

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 :)

travelmassive avatar Jul 03 '19 04:07 travelmassive

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

jonaswebdev avatar Oct 30 '20 23:10 jonaswebdev

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;
}

donbowman avatar Mar 04 '23 23:03 donbowman