代码及使用方式
打开自己正在使用的主题的文件目录(/wp-content/themes/主题名)找到functions.php。编辑functions.php在底部加入下面的代码:
/* 检查百度是否已收录文章页面 最先*/
function baidu_check($url){
$url=\'http://www.baidu.com/s?wd=\'.$url;
$curl=curl_init();
curl_setopt($curlCURLOPT_URL$url);
curl_setopt($curlCURLOPT_RETURNTRANSFER1);
$rs=curl_exec($curl);
curl_close($curl);if(!strpos($rs\'没有找到\')){return 1;
}else{return 0;
}
}function baidu_record() {if(baidu_check(get_permalink()) == 1) {echo \'<a target=\"_blank\" title=\"点击查看\" rel=\"external nofollow\" href=\"https://www.baidu.com/s?wd=\'.get_the_title().\'\">百度已收录</a>\';
} else {echo \'<a style=\"color:red;\" rel=\"external nofollow\" title=\"一键协助提交给百度谢谢您!\" target=\"_blank\" href=\"https://zhanzhang.baidu.com/sitesubmit/index?sitename=\'.get_permalink().\'\">百度未收录</a>\';
}
}
挪用方式:
<?php baidu_record();?>
添加到你想要显示的位置!上面的代码添加完成后将插入到需要显示收录提醒的地方一样平时文章模板是single.php页面模板是page.php。添加好后刷新页面收录提醒能够正常显示就说明ok了。