WordPress.org

Ready to get started?Download WordPress

Forums

Add noindex tag to pages (7 posts)

  1. Dantes100
    Member
    Posted 5 years ago #

    Hi,

    Is there a plugin where I can add a noindex tag to certain pages, which I do not want to be found on search engines?

    Is there another method, if there is no plugin?

    Eddie

  2. moronicbajebus
    Member
    Posted 5 years ago #

    Do you want to add noindex to certain posts or to a certain types of pages (eg. archive pages)?

    If it is the first one, try this plugin: Noindex specific posts and pages. If it is the second, you can add it in you theme header.php and conditional check which type it is:

    <?php if(is_single()): ?>
    <META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW" />
    <?php endif; ?>
  3. Hiranthi
    Member
    Posted 5 years ago #

    A while ago I implemented some code in the theme of a client of mine who wanted exactly the same thing.
    I used a custom field for it (if the custom field was activated the page-link should have a no-follow) and used a custom query to display the page-navigation (and use an if statement to see if the custom-field was activated or not (true or false input btw)).

    Here's the code:

    <?php $query = "SELECT * FROM $wpdb->posts WHERE $wpdb->posts.post_status = 'publish' AND $wpdb->posts.post_type = 'page' ORDER BY $wpdb->posts.menu_order ASC";
    $pageposts = $wpdb->get_results($query, OBJECT);
    
    if ($pageposts):
    	foreach ($pageposts as $post):
    		setup_postdata($post);
    
    		$value = get_post_custom_values('p_nofollow');
    		if ( $value[0] == 'true' ) { $nofollow = ' rel="nofollow"'; } else { $nofollow = ''; }
    
    		if ( is_page( $post->ID ) ) {
    			?><li class="page_item page-item-<?php echo $post->ID; ?> current_page_item"><a<?php echo $nofollow ?> href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></li><?php
    		}
    		else
    		{
    			?><li class="page_item page-item-<?php echo $post->ID; ?>"><a<?php echo $nofollow ?> href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></li><?php
    		}
    	endforeach;
    endif;
    ?>

    If it's not (just) the links you want to add a nofollow rel to, I can recommend the robots meta plugin moronicbajebus is pointing to.

  4. Dantes100
    Member
    Posted 5 years ago #

    Great, exactly what I needed!

    Thank you guys!

  5. waterhasnoenemy
    Member
    Posted 5 years ago #

    Hey, guys, I was lost reading this post. I am not techie at all. Please can you simply tell me which pages to check the "noindex" in All in one SEO?

    Thanks.

    Jackson.

  6. waterhasnoenemy
    Member
    Posted 5 years ago #

    Hey, guys, I was lost reading this post. I am not techie at all. Please can you simply tell me which pages to check the "noindex" in All in one SEO? While I checked all except "category".

    Thanks.

    Jackson.

  7. Boris Beo
    Member
    Posted 5 years ago #

    illutic,

    I did the same thing (noindex, nofollow appears based on a custom field value). But I did it slightly different ;)

    For all of you wishing to exclude a page or a post from being crawled and indexed by Google or other search engines, do the following.

    Add the following code to your header.php (in your theme folder):

    <?php
    $status = get_post_meta($post->ID, 'Publish', true);
    if ($status == '')
    { ?>
    <?php } else { ?>
    <meta name="robots" content="noindex,nofollow" />
    <?php } ?>

    When publishing a page or a post that you don't want to be indexed by the search engines, add a custom field called 'Publish' to your page or post (ie. custom field: Publish, value: noindex - although it doesn't matter what the value is).

    Pages and posts without the custom field 'Publish' added will not be affected. Pages and posts with the custom field 'Publish' will not be indexed.

    Hope this helps.

Topic Closed

This topic has been closed to new replies.

About this Topic