How to Exclude Taxonomies from Yoast SEO Sitemap?

Do you want to exclude taxonomies from the Yoast SEO sitemap in WordPress?

Why Exclude Taxonomies from the Yoast SEO Sitemap?

Excluding taxonomies from the Yoast SEO sitemap can be beneficial for several reasons:

Reduce Sitemap Size

Crawling large sitemaps affects the crawl efficiency of search engine bots. Removing taxonomies from the sitemap streamlines the sitemap.

Avoid Duplicate Content Issues

Each taxonomy has its own page, with duplicate content already populated on posts. To prevent duplication of the content. The taxonomies should be excluded from the Yoast SEO sitemap.

Enhance SEO Focus

By excluding certain taxonomies, you can ensure that search engines focus on the most valuable and relevant content on your site, which can improve your SEO results.

Code Snippet to Exclude One Taxonomy From Yoast SEO Sitemap

php
/**
 * Exclude One Taxonomy From Yoast SEO Sitemap
 *
 * @param string $value
 * @param string $taxonomy
 * @return boolean
 */
function maverick_sitemap_exclude_taxonomy($value, $taxonomy)
{
    // Check if taxonomy is equal to custom taxonomy slug
    if ($taxonomy == 'taxonomy_slug') {
        return true;
    }
}

add_filter('wpseo_sitemap_exclude_taxonomy', 'maverick_sitemap_exclude_taxonomy', 10, 2);

Code Snippet to Exclude Multiple Taxonomies From Yoast SEO Sitemap

php
/**
 * Exclude Multiple Taxonomies From Yoast SEO Sitemap
 *
 * @param string $value
 * @param string $taxonomy
 * @return boolean
 */
function maverick_sitemap_exclude_taxonomies($value, $taxonomy)
{
    // List of taxonomies to exclude from sitemap
    $taxonomy_to_exclude = array('taxonomy_slug1', 'taxonomy_slug2', 'taxonomy_slug3');

    // Check if taxonomies exists in exlusion list
    if (in_array($taxonomy, $taxonomy_to_exclude)) {
        return true;
    }
}

add_filter('wpseo_sitemap_exclude_taxonomy', 'maverick_sitemap_exclude_taxonomies', 10, 2);

Leave a Reply

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