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
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?
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.
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 ?>
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?
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
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.
Thank you. I was having a hard time figuring out what went wrong. From now on, I will include the closing bracket. Topic solved.