WordPress Development Asked by Summer Pratt on November 26, 2021
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!
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.
Answered by t2pe on November 26, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP