• Resolved Roman Klabal

    (@klabson)


    Hi Sybre,
    thanks for your awesome plugin.

    Can you please help me with excluding certain links (in my case they are specific post IDs of a certain CPT, but I guess the process will be the same for any other links) from the Sitemap?

    I tried using the the_seo_framework_query_supports_seo but could not get it to work. I am not even sure if its the correct filter, as the “Disable SEO support” title is a bit ambiguous and I am not even sure what exactly does that mean.

    Would setting noindex and nofollow via the_seo_framework_robots_meta_array work, or not? I tried looking through the docs, but no dice.

    Thank you in advance!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Sybre Waaijer

    (@cybr)

    Hi Roman,

    the_seo_framework_query_supports_seo only supports the “main query” or loop, and since sitemap generation consists of many queries and no loop, we need to look elsewhere.

    Every post you redirect or apply noindex to will be excluded from the sitemap; no filters are required in this process. But, if you still wish to have the CPT items indexed, then you must resort to custom coding.

    When you have a standard list of IDs you wish to exclude, then you need to forward all those IDs at once via the_seo_framework_sitemap_exclude_ids.

    Alternatively, if you wish to evaluate on a per-post basis, you could use the filter you already found, the_seo_framework_robots_meta_array, and overwrite the return value’s ['noindex'] array-index. Regardless, TSF has no hook/signal that allows you to detect whether a sitemap is being generated, so this is hacky. Also, note that this filter executes for every single post, so be mindful about inserting slow code. Don’t hesitate to ask for pointers if you must go this route.

    Either way, let me know if you require assistance or wish me to verify your code for unexpected side effects! Cheers ??

    Thread Starter Roman Klabal

    (@klabson)

    Hi Sybre,
    the the_seo_framework_sitemap_exclude_ids is exactly what I was looking for, strange that I wasnt able to find it when searching for it yesterday.

    Attaching a snippet that excludes IDs of a specific CPT that have a specific ACF condition met. Maybe someone will find it useful.

    add_filter('the_seo_framework_sitemap_exclude_ids', 'prefix_the_seo_framework_sitemap_exclude_ids');
    function prefix_the_seo_framework_sitemap_exclude_ids() {
        $ids = [];
        $excluded = get_posts([
            'post_type'     => 'my_cpt',
            'numberposts'   => -1,
            'post_status'   => 'publish',
            'meta_key'      => 'my_acf_true_false_field',
            'meta_value'    => 0
        ]);
        if (count($excluded) > 0) {
            $ids = wp_list_pluck($excluded, 'ID');
        }
    
        return $ids;
    }

    Then I re-saved the SEO settings page to force a new sitemap and it worked perfectly.

    Thank you very much for your help and for your awesome plugin!

    Hi Roman

    I found your explanation very helpful –?thank you so much

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to exclude links from the sitemap?’ is closed to new replies.