• Resolved indieisnotagenr

    (@indieisnotagenr)


    Hi,

    I would like to noindex all archive pages that have less than a certain number of posts. Can anyone help me with the code? I’ve tried this but it’s not working:

    ` function wpseo_robots( $robotsstr ) {
    if ( is_tag() && ( wp_count_posts()->publish < 5 ) ) {
    return ‘noindex,nofollow’;
    }
    return $robotsstr;
    }

    Cheers

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Support amboutwe

    (@amboutwe)

    wp_count_posts()->publish retrieves the number of published posts on the entire site. You’ll want to retrieve the number of published posts for the specific tag for the archive page that is being displayed.

    Try get_queried_object()->count instead of wp_count_posts()->publish.

    If that doesn’t work, we recommend investigation how to retrieve the number of published posts for a specific tag. If you need a developer, we recommend checking out Code Poet, WordPress Jobs, or WordPress Professional Network for development & consultancy.

    • This reply was modified 4 years, 7 months ago by amboutwe.
    Thread Starter indieisnotagenr

    (@indieisnotagenr)

    Thanks, that did it! Here’s the full code I used:

    add_filter("wpseo_robots", function($robots) {
    if ( is_tag() && ( get_queried_object()->count < 5 ) ) {
      return "noindex,follow";
    }
    return $robots;
    });
    Thread Starter indieisnotagenr

    (@indieisnotagenr)

    I’m now getting an error in Google Search Console because the noindexed pages still appear in the sitemap. Is there any way to exclude them using the filter_wpseo_sitemap_exclude_empty_terms or another filter?

    Hi,

    By default Yoast does not output Archive Pages on the sitemap. If they are we would like to learn more about this issue. We would like some more information.

    1. Can you provide a link to the website that has the archive pages appearing on the sitemap?

    2. Can you provide an example of an archive page URL that Google is flagging?

    3. Can you describe exactly what Google Search Console is saying? What is the exact error?

    Plugin Support devnihil

    (@devnihil)

    We are going ahead and marking this issue as resolved due to inactivity. If you require any further assistance please create a new issue.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Noindex archive pages with less than X posts’ is closed to new replies.