Hi, Google!
I realized that my default theme, a heavily modified version of Back in Black 2, is a little unfriendly towards search engines since it’s so heavy on the Javascript. I’ve written a plugin to automatically override the theme back to “default” when a search engine hits it.
Note that I’m hardcoding the bot domains. What I’ve done elsewhere is an Apache rewrite from robots.txt to robots.cgi, which then logs the bot in a MySQL database and spits out the real robots.txt. isengine() just checks the MySQL database to see if $REMOTE_HOST has snarfed robots.txt lately. It works pretty well. I chose to hardcode here just for simplicity.
Code follows.
<?php
/*
** Plugin Name: Theme Engine
** Plugin URI: http://www.datanorth.net/~cuervo/blog/
** Description: Automatically switches to the "default" theme for search engines
** Version: 0.1
** Author: Johnny Cuervo
** Author URI: http://www.datanorth.net/~cuervo/blog/
**
** So, my theme is apparently sort of horked for Google, since it's heavy
** on the Javascript. I wrote this plugin to play nice.
**
** - JC
*/
$engines = array(
'googlebot.com',
'yahoo.com',
'live.com',
'exabot.com',
'yahoo.net'
);
function fastone_isengine ()
{
global $engines;
/*
** Reduce $remote to domain name
*/
$remote = $_SERVER['REMOTE_HOST'];
$rdom = preg_split('/\./', $remote);
while (count($rdom) != 2)
{
array_shift($rdom);
}
$rdom = $rdom[0] . '.' . $rdom[1];
foreach ($engines as $e)
{
if (strcmp($rdom, $e) == 0)
{
return true;
}
}
return false;
}
function pull_fastone_template ($template)
{
if (fastone_isengine())
{
return "default";
}
return $template;
}
function pull_fastone_stylesheet ($stylesheet)
{
if (fastone_isengine())
{
return "default";
}
return $stylesheet;
}
add_filter('template', 'pull_fastone_template', 1);
add_filter('stylesheet', 'pull_fastone_stylesheet', 1);
?>

No comments yet.