Forums

[resolved] Prevent google from reading comment... (13 posts)

  1. indiaberry
    Member
    Posted 2 years ago #

    How do I prevent google from reading comments on my website? I don't mind google listing my site. I post an uncommon name on my website, and google track that word directly to my website. And since then, when I put that word in the google search, it come directly to my website. How do I keep google from reading my comment?

  2. whooami
    Member
    Posted 2 years ago #

    The ONLY way you can do that is by checking the user-agent and hiding content based on the user-agent.

    Here's something to get your brain in thinking mode:

    $useragent = $_SERVER['HTTP_USER_AGENT'];
    $google = "Googlebot";
    $isgoogle = strpos($useragent, $google);
    If ($isgoogle === false) {
    //not a Google hit
    } else {
    //This is Google
  3. indiaberry
    Member
    Posted 2 years ago #

    Where should I put that code?

  4. whooami
    Member
    Posted 2 years ago #

    "Here's something to get your brain in thinking mode"

    Doesnt sound like youre thinking, sounds like you want someone to do this for you?

  5. indiaberry
    Member
    Posted 2 years ago #

    Should it go in the .htaccess file? Does it go in the index.php of the theme? Could I have a little more hint?

  6. pravin
    Member
    Posted 2 years ago #

    That is php code. It can go in one of two places

    1. index.php, page.php, single.php, etc before the comment code

    2. start of comment.php

    I'd pick 2 because it involves changing only 1 file.

  7. indiaberry
    Member
    Posted 2 years ago #

    Hi! When I tried the code, the words show up on the page. How do I insert the code. I know how to edit a file. But what I don't know is if I need to put the code in this <php ?>

  8. indiaberry
    Member
    Posted 2 years ago #

    It is just that I put that code in the comment.php, it show up on the page of where the comments are. I am wondering what is the best way to insert the code?

  9. indiaberry
    Member
    Posted 2 years ago #

    I need a bit more help with this code, please.

  10. adam-
    Member
    Posted 2 years ago #

    Put it all inside <? php ?> tags and tbh I haven't looked into it but if theres something like include(comments.php) then put the comments include in the // not a google hit. Oh, and I'm not a php coder but it's something like that ^^

    Adam

  11. indiaberry
    Member
    Posted 2 years ago #

    When I put this in:
    <?php $useragent = $_SERVER['HTTP_USER_AGENT'];
    $google = "Googlebot";
    $isgoogle = strpos($useragent, $google);
    If ($isgoogle === false) {
    //not a Google hit
    } else {
    //This is Google
    ?>

    I get:
    Parse error: syntax error, unexpected $end in /home/domainname/public_html/writer/wp-content/themes/girl/comments.php on line 113

  12. whooami
    Member
    Posted 2 years ago #

    <?php $useragent = $_SERVER['HTTP_USER_AGENT'];
    $google = "Googlebot";
    $isgoogle = strpos($useragent, $google);
    If ($isgoogle === false) {
    //not a Google hit
    } else {
    //This is Google
    }
    ?>

    Missing closing bracket.

  13. indiaberry
    Member
    Posted 2 years ago #

    Thank you. I was having a hard time figuring out what went wrong. From now on, I will include the closing bracket. Topic solved.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.