• does anyone know how i can restrict google from posts created by certain authors??

    is it possible??

    by robot txt

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator keesiemeijer

    (@keesiemeijer)

    Try it with this in your theme’s functions.php if you don’t have any other plugins that add robots meta tags:

    add_action('wp_head', 'restrict_author');
    function restrict_author() {
    
      $restricted_author_ids = array(18,24);
    
      if(is_single() || is_page()){ // single posts, pages
        global $post;
        if(isset($post->post_author) && (in_array($post->post_author, $restricted_author_ids))){
          echo '<meta name="robots" content="noindex, follow">'."\n";
        }
    
      }
    
      if(is_author($restricted_author_ids )) { // author archive page
        echo '<meta name="robots" content="noindex, follow">'."\n";
      }
    
    }

    Change the author IDs to the correct author IDs in:

    $restricted_author_ids = array(18,24);

    Thread Starter kitcorsa

    (@kitcorsa)

    cheers, where do i get author ids from?

    Moderator keesiemeijer

    (@keesiemeijer)

    Go to wp-admin > Users > All Users and click on a user (author) you want to exclude. In the address bar of your browser you will see something similar to this

    /user-edit.php?user_id=9&wp_http_referer=%2Fwp-admin%2Fusers.php

    The user id is the number after ‘user_id=’.

    The results of this will probably be visible after google has crawled your website.

    Check the source code of your website to see if the code is only added on the single posts, pages and author pages that you want to exclude.

    Thread Starter kitcorsa

    (@kitcorsa)

    how can I change the code so i can exclude a certain google bot?? ie i want to exclude the google news bot to certain posts

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘restrict google to certain author posts?’ is closed to new replies.