brainstormforce / unlist-posts

Hide post from displaying anywhere on the site, only access the post with a direct link to the post.
https://wordpress.org/plugins/unlist-posts/
17 stars 5 forks source link

Hide unlisted posts from Yoast SEO sitemap #28

Open Nikschavan opened 6 years ago

travelmassive commented 5 years ago

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

jonaswebdev commented 3 years ago

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

donbowman commented 1 year ago

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