admin管理员组

文章数量:1122847

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; 
endif;?>

Any ideas? Thank you in advance!

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; 
endif;?>

Any ideas? Thank you in advance!

Share Improve this question asked Jul 22, 2020 at 14:00 Summer PrattSummer Pratt 1
Add a comment  | 

1 Answer 1

Reset to default 0

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.

本文标签: seoHow can I noindex my archive pages