How to deny disallow block Googlebot (Google) to see some content (how to hide content from google)
----------
Similar topic: ban google to view entire/whole page
----------
Hello,
is there any ways how to disallow search engine bots to index some part of html code? I mean i need to have an block of advertising links on my site and i dont want them to make me Pagerank 0 so i want to hide the content from Google..
One way is nofollow attribute to the links, but i cant use it and its not what im looking for (hidding content from google), so here i found a few ways (im not sure if they work properly, you must veriffy it):
#1
Instead of block of text links, generate a new iframe like:
Code:
<iframe src="http://mysite.com/ads.html" style="border:0px #FFFFFF none;" name="ngbot" scrolling="no" frameborder="0" marginheight="0px" marginwidth="0px" width="100%"></iframe>
and create new page ads.html and paste your ads/txt links there.
Then into robots.txt fille add disallow rule for this file like:
Code:
User-agent: Googlebot
Disallow: /ads.html
#2
php way 1
Code:
Visible to googlebot
<script type="text/javascript">
document.write ("<?php echo base64_encode('<b>Invisible to googlebot</b>'); ?>");
</script>
#3
php way 2 - if user agent is not googlebot, then show the ads
Code:
if(!strstr(strtolower($_SERVER['HTTP_USER_AGENT']), "googlebot")) {
echo "Ads text and links without quotation marks or commented out";
}
#4
php way 3 (my favorite, tested)
Code:
if (strpos($_SERVER['HTTP_USER_AGENT'],'Google') == false) { echo '
ALL CONTENT THAT SHOULD BE HIDDEN FROM GOOGLE BOTS HERE
AND HERE TOO
'; }
all apostrophes ( ' ) in your google hidden content must be commented out ( \' )
If want to hide content from multiple bots, one may try:
Code:
if (strpos($_SERVER['HTTP_USER_AGENT'],'Google') == false || strpos($_SERVER['HTTP_USER_AGENT'],'Yahoobot') == false || strpos($_SERVER['HTTP_USER_AGENT'],'Microsoftbot') == false || strpos($_SERVER['HTTP_USER_AGENT'],'msnbot') == false || strpos($_SERVER['HTTP_USER_AGENT'],'SeznamBot') == false) { echo '
ALL CONTENT THAT SHOULD BE HIDDEN FROM GOOGLE BOTS HERE
AND HERE TOO
'; }
If want to show ad/hiddent content only on certain subpages/urls, following code can be used:
This is hidding from Google, Yahoo, MSN (at least i believe) + show content only on certain pages/subpages/index
Code:
if (strpos($_SERVER['HTTP_USER_AGENT'],'Google') == false || strpos($_SERVER['HTTP_USER_AGENT'],'Yahoobot') == false || strpos($_SERVER['HTTP_USER_AGENT'],'Microsoftbot') == false || strpos($_SERVER['HTTP_USER_AGENT'],'msnbot') == false || strpos($_SERVER['HTTP_USER_AGENT'],'SeznamBot') == false) {
function getAddress() {
$protocol = $_SERVER['HTTPS'] == 'on' ? 'https' : 'http';
return $protocol.'://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
}
switch (getAddress())
{
case "http://domain.com/page.php?xx=something":
echo 'some html code to show there';
break;
case "some other exact url here":
echo 'some html code to show there';
break;
default:
echo '<!-- Google see this -->';
}
}
// end
# 5
Smarty way
Code:
{php}
if (strpos($_SERVER['HTTP_USER_AGENT'],'Google') == false) { echo '
ALL CONTENT THAT SHOULD BE HIDDEN FROM GOOGLE BOTS HERE
AND HERE TOO
'; }
{/php}
# 6
Wordpress sidebar way
Wordpress / Editor /
in index.php and single.php template i had:
<?php include (TEMPLATEPATH . '/right-sidebar.php'); ?>
so i hidden right sidebar from google by including it only if not googlebot:
<?php if (strpos($_SERVER['HTTP_USER_AGENT'],'Google') == false) { include (TEMPLATEPATH . '/right-sidebar.php'); } ?>
It not add nofollow links to Wordpress sidebar, but it hide it compeltelly from visitor with user agent containing "Google".
If one have links that want to hide in text widget, one can use html code above or use Wordpress plugin that allow embeding PHP code in widgets (i.e.Samsarin plugin) + use php hide code above
# 7
vBulletin way
(Forums & Moderators / Form blocks manager / SomeBlockhere / Content type -> PHP)
if (strpos($_SERVER['HTTP_USER_AGENT'],'Google') == false || strpos($_SERVER['HTTP_USER_AGENT'],'Bing') == false || strpos($_SERVER['HTTP_USER_AGENT'],'Microsoft') == false) {
$html = '
<a href="http://www.domain.tld">anchor</a> text here ... you\'re looking for something. Note that single quotation marks are commented out by backslash (\) but there is pipe (|) instead which is wrong. Double quotation mark not commented.
';
return $html;a
}
# 8
PHPBB way
(before one need to enable "Allow php in templates:" in Admin control panel / General / Security Settings!!)
<!-- PHP -->
if (strpos($_SERVER['HTTP_USER_AGENT'],'Google') == false) {
function getAddress() {
$protocol = $_SERVER['HTTPS'] == 'on' ? 'https' : 'http';
return $protocol.'://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
}
switch (getAddress())
{
case "http://domain.com/page.php?xx=something":
echo 'some html code to show there';
break;
case "some other exact url here":
echo 'some html code to show there';
break;
default:
echo '<!-- Google see this -->';
}
}
<!-- ENDPHP -->
(so this includes cases, mean if certain url is, then show certain code.., if partial url match is required, one may try:
if (stristr($a,'viewtopic'))
echo 'yes we are on viewtopic page';
)
if (!stristr($a,'casino'))
echo 'yes we are NOT in casino section';
)
To veriffy Google bot dont see the links, use Fetch as Googlebot feature in Webmaster tool Crawl menu.
- On the Webmaster Tools Home page, click the site you want.
- On the Dashboard, under Crawl, click Fetch as Google.
notes:
botname('Googlebot');
botname('Googlebot-Mobile');
botname('Googlebot-Image');
botname('Mediapartners-Google');
botname('Adsbot-Google');
botname('Yahoobot');
botname('Microsoftbot');
botname('msnbot');
botname('msnbot-media');
botname('Slurp');
botname('SeznamBot');
Bookmarks