How to Exclude Post Type(s) from Yoast SEO Sitemap?

Do you want to exclude post type(s) from the Yoast SEO sitemap in WordPress?

Yoast SEO includes all post types in the Yoast SEO sitemap by default. However, in some cases, you may want to exclude certain post types from the Yoast SEO sitemap.

Why Exclude Post Types from Yoast SEO Sitemap?

Excluding certain post types from the Yoast SEO sitemap in WordPress can be beneficial for multiple reasons. Here are some scenarios and rationales for why you might choose to exclude specific post types:

1. Irrelevant Content for SEO

Some post types, such as testimonials, FAQs, or portfolio items, may not provide significant SEO value and need to be excluded from indexing by search engines.

2. Duplicate Content

Certain post types may result in duplicate content and confuse search engines, which can affect your SEO efforts. For example, if you have a custom post type that replicates some part of your regular post content, it may be wise to exclude it from the sitemap.

3. Internal or Private Content

Internal team content or private content, such as staff bios, memos, or drafts, that you don’t want search engines to index should be excluded from the Yoast SEO sitemap.

4. Low-Quality Content

Low-quality content or thin content that doesn’t provide substantial value should be excluded from the Yoast SEO Sitemap to prevent them from negatively impacting your site’s overall SEO performance.

5. Staging or Development Content

Content created for staging, development, or testing purposes should be excluded from the Yoast SEO sitemap so that search engines don’t index it.

6. Enhanced Crawl Efficiency

Every search engine has a crawl budget, i.e., the number of pages crawled by a search engine on a website within a given time. Excluding less important post types helps search engines spend their crawl budget more efficiently on the most valuable and important content.

7. User-Generated Content

User-generated content, such as reviews, comments, or forum posts, should be excluded to keep the SEO performance intact.

Code Snippet to Exclude One Post Type From Yoast SEO Sitemap

    php
    /**
     * Exclude One Post Type From Yoast SEO Sitemap
     *
     * @param string $value
     * @param string $post_type
     * @return boolean
     */
    function maverick_sitemap_exclude_post_type($value, $post_type)
    {
        // Check if post type is equal to custom post type slug
        if ($post_type == 'post_type_slug') {
            return true;
        }
    }
    
    add_filter('wpseo_sitemap_exclude_post_type', 'maverick_sitemap_exclude_post_type', 10, 2);

    Code Snippet to Exclude Multiple Post Types From Yoast SEO Sitemap

    php
    /**
     * Exclude One Post Types From Yoast SEO Sitemap
     *
     * @param string $value
     * @param string $post_type
     * @return boolean
     */
    function maverick_sitemap_exclude_post_types($value, $post_type)
    {
        // List of post type slugs to exclude from Yoast SEO Sitemap
        $post_types_to_exclude = array('post_type_slug1', 'post_type_slug2', 'post_type_slug3');
    
        // Check if post types exists in exlusion list
        if (in_array($post_type, $post_types_to_exclude)) {
            return true;
        }
    }
    
    add_filter('wpseo_sitemap_exclude_post_type', 'maverick_sitemap_exclude_post_types', 10, 2);

    Leave a Reply

    Your email address will not be published. Required fields are marked *