LATEST >>

Welcome Here And Thanks For Visiting. Like Us On Facebook...

EXEIdeas – Let's Your Mind Rock » WordPress / WordPress Tips / WordPress Tricks » NoIndex/NoFollow For Specific Author Posts In WordPress Without Plugin?

NoIndex/NoFollow For Specific Author Posts In WordPress Without Plugin?

NoIndex-NoFollow-For-Specific-Author-Posts-In-WordPress-Without-Plugin
If you don’t want to index specific posts and pages, categories, and tags of your site, there are two methods to do so. The easiest one is by disallowing through robots.txt. The second is by adding meta tags to disallow pages/posts globally. In the manual method, we will add the below meta tag to the header of each page you want to block from being indexed.

So its time to simply exclude all author posts from indexing in SERPs. This code allows you to noindex and nofollow posts for certain authors without modifying the code and it works with most of the available themes. Just copy and paste the code to add noindex and nofollow meta for all author posts.

There are many code snippets available online or on many other blogs and websites, but everyone cannot optimize your blog or website, so you need some optimized code snippets. So now checkout out the code snippet for your blog and website that will give you all features for your desired code. Now grab the ready-to-use code and paste it where you want.

Table of Contents

Features:

  1. Light Weight.
  2. Pure PHP Code.
  3. Cross Browser.
  4. No Plugin Files.
  5. Fully Customizable.
  6. No External Links.

How To NoIndex/NoFollow For Specific Author Posts In WordPress Without Plugin?

There are a few easy and understandable steps to achieve your desired functionality that we are gonna share below. Follow each step perfectly.

header.php

<!-- NoIndex/NoFollow For Specific Author Post For WordPress By EXEIdeas Start -->
<?php if (have_posts()):while(have_posts()):the_post(); endwhile; endif;?>
<!-- The Default Values -->
<?php if (is_single()) { ?>
<!-- Only For Content Pages -->
<?php
$authorsList = array("Author_1", "Author_2", "Author_3", "Author_4");
if (in_array(get_the_author(), $authorsList)) {
echo '<META NAME="robots" CONTENT="noindex,nofollow">';
} else {
//echo get_the_author();
}
?>
<?php } else { ?>
<!-- For All Pages Expect Content Page -->
<?php } ?>
<!-- NoIndex/NoFollow For Specific Author Post For WordPress By EXEIdeas End -->

Alternate Way:

functions.php

add_action('wp_head','AS_exclude_author_from_indexing');
function AS_exclude_author_from_indexing(){
  $toIndex = array(111,112,113);
  $user_id = get_the_author_meta( 'ID' );
  if( !in_array($user_id,$toIndex)){
    echo "<meta name=\"robots\" content=\"noindex,follow\">".PHP_EOL;
  } 
}
---OR---
/* NoIndex/NoFollow For Specific Author Post For WordPress By EXEIdeas Start */
add_action('wp_head','AS_exclude_author_from_indexing');
function AS_exclude_author_from_indexing(){
  $authorsList = array("Author_1", "Author_2", "Author_3", "Author_4");
  if (in_array(get_the_author(), $authorsList)) {
    echo PHP_EOL."<meta name=\"robots\" content=\"noindex,follow\">".PHP_EOL;
  } 
}
/* NoIndex/NoFollow For Specific Author Post For WordPress By EXEIdeas End */

Customization:

No need to customize it. Just copy-paste. Rest edit the code as per comments and need.

Troubleshooting the Errors:

Do it with concentration and patience. Check your all steps again and all codes or scripts. If you find any error you can contact us anytime via comment or better via email, We are always here to help you.

Recommended For You:
Why WordPress Can't Outperform A Learning Management System?

Final Words:

That’s all we have. We hope that you liked this article. If you have any problem with this code in your template then feel free to contact us with a full explanation of your problem. We will reply to you as time allows us If you have any doubts or problems please comment below. We are happy to help you! If you liked this article, Don’t forget to share this with your friends so they can also take benefit from it and leave.

You Like It, Please Share This Recipe With Your Friends Using...

Be the first to write a comment.

Leave a Reply

Your email address will not be published. Required fields are marked *