这里有一个编程方法。它的作用是检查ajax请求是否正在运行,以及useragent是否在定义的白名单中,如果在白名单中,它将继续正常加载wp,否则它将死亡。我使用registered\\u分类法,因为它是钩子加载过程中的第二个钩子:
http://codex.wordpress.org/Plugin_API/Action_Reference
我将把它添加到主题函数中。php和测试:
/* Disable AJAX for Spiders */
add_action( \'registered_taxonomy\' , \'disable_ajax_for_spiders\' );
function disable_ajax_for_spiders() {
if ( !defined(\'DOING_AJAX\') || !DOING_AJAX ) {
return;
}
if ( !isset($_SERVER[\'HTTP_USER_AGENT\']) ) {
return;
}
$visitor_useragent = strtolower($_SERVER[\'HTTP_USER_AGENT\']);
$useragents[] = \'msie\';
$useragents[] = \'firefox\';
$useragents[] = \'webkit\';
$useragents[] = \'opera\';
$useragents[] = \'netscape\';
$useragents[] = \'konqueror\';
$useragents[] = \'gecko\';
$useragents[] = \'chrome\';
$useragents[] = \'songbird\';
$useragents[] = \'seamonkey\';
$useragents[] = \'flock\';
$useragents[] = \'AppleWebKit\';
$useragents[] = \'Android\';
$useragents[] = \'Lynx\';
$useragents[] = \'Dillo\';
/* If useragent in list then bail - else die() immediately*/
if ($visitor_useragent)
{
foreach ($useragents as $k=>$useragent)
{
$useragent = trim($useragent);
if ($useragent)
{
if(stristr($visitor_useragent, $useragent)||$useragent==\'*\')
{
return;
}
}
}
}
die();
}