How do you hide links from search engine bots in ajax?

michaelr1988

Regular Member
Joined
Apr 25, 2011
Messages
489
Reaction score
317
How do you hide links from search engine bots in ajax? I have 3 links in my footer that I want to be visible to visitors but hidden from search engine bots. Anyone can point me in the right direction of a easy to follow guide, been struggling with this for a couple of hours now.

Cheers.
 
By ajax I assume you mean JavaScript. You can get the user agent string from a visitor, but the problem is that not all crawlers/spiders use JavaScript. So the best option here is, if you can, to use something like the following PHP script:

Code:
<?php
function isUserBot() {
    $bots = array(
        'googlebot',
        'bing'
        // Whatever the other bots' user agents are
    );

    foreach ($bots as $bot) {  
        if (strstr(strtolower($_SERVER['HTTP_USER_AGENT']), $bot)) return true;
    }

  return false;
}
?>

And then just
Code:
<?php if (!isUserBot()) : ?>
<a href="#">Link 1</a> | <a href="#">Link 2</a> | ...
<?php endif; ?>
 
Back
Top