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?
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
indiaberry
Member
Posted 2 years ago #
Where should I put that code?
"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?
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?
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.
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 ?>
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?
indiaberry
Member
Posted 2 years ago #
I need a bit more help with this code, please.
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
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
<?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.
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.