here are the steps to exclude specific post types from the Yoast SEO sitemap:
1. Use the Yoast SEO Plugin Settings:
- In the WordPress admin dashboard, go to SEO > Search Appearance > Content Types.
- Scroll down to the "Exclude from Sitemap" section.
- Enter the post type slugs you want to exclude, separated by commas.
- Save the changes.
2. Use a Custom Plugin or Functions.php:
- Create a custom plugin or add the following code to your theme's `functions.php` file:
php
add_filter( 'wpseo_sitemap_exclude_post_type', 'sitemap_exclude_post_type', 10, 2 );
function sitemap_exclude_post_type( $value, $post_type ) {
if ( $post_type == 'post_type_slug' ) {
return true;
}
return $value;
}
- Replace `'post_type_slug'` with the slug of the post type you want to exclude.
- You can also exclude multiple post types by adding more conditions in the `if` statement.
3. Use the `wpseo_sitemap_exclude_post_type` Filter:
- You can use the `wpseo_sitemap_exclude_post_type` filter to exclude specific post types from the Yoast SEO sitemap.
- Here's an example of how to exclude the `product` and `core37_lp` post types:
php
add_filter( 'wpseo_sitemap_exclude_post_type', 'sitemap_exclude_post_type', 10, 2 );
function sitemap_exclude_post_type( $value, $post_type ) {
$post_types_to_exclude = array('product', 'core37_lp');
if ( in_array( $post_type, $post_types_to_exclude ) ) {
return true;
}
return $value;
}
4. Exclude Individual Posts or Pages:
- In the Yoast SEO metabox for a specific post or page, expand the "Advanced" section.
- Change the "Allow search engines to show this Post in search results?" option to "No".
- This will exclude the individual post or page from the Yoast SEO sitemap.
By following these steps, you can effectively exclude specific post types or individual posts and pages from the Yoast SEO sitemap.
Citations:[1] https://www.binarycarpenter.com/how-to-exclude-custom-post-types-posts-pages-from-yoast-seo-sitemap/
[2] https://wordpress.stackexchange.com/questions/243476/exclude-custom-post-type-in-sitemap-generation
[3] https://stackoverflow.com/questions/44530358/wordpress-yoast-exclude-posts-from-xml-sitemap
[4] https://yoast.com/help/sitemap-shows-excluded-posts-pages/
[5] https://developer.yoast.com/customization/yoast-seo/filters/cornerstone-post-types-filter/