I am using the following snippet in my functions.php.

function add_noindex() {
    if(is_archive()) {
        echo '<meta name="robots" content="noindex,follow" />';
add_action( 'wp_head', 'add_noindex' );

I thought this would noindex all my archive pages, but it is not working. My archive page code looks like this:

<?php get_header(); ?>
<h1><?php single_cat_title();?></h1>

<?php if (have_posts()) : while(have_posts()) : the_post();?>
    <h3><?php the_title();?></h3>
    <?php the_excerpt();?>
    <a href="<?php the_permalink();?>">Read More</a>
<?php endwhile; 

Any ideas? Thank you in advance!


This worked ok for me, putting this function into a vanilla build using TwentyTwenty? I see the output in the Head.

Its very crude but inside your IF statement, add some form of simple debug, either var_dump() a string out or Javascript console.log. You're testing to make sure the IF is activating when you think it is. Also consider using the Show Current Template plugin as this would highlight if you weren't using the template you expected to when visiting the page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.