代码及使用方法
打开自己正在使用的主题的文件目录(/wp-content/themes/主题名),找到functions.php。编辑functions.php,在底部加入下面的代码:
function baidu_check($url){ $url='http://www.baidu.com/s?wd='.$url; $curl=curl_init(); curl_setopt($curl,CURLOPT_URL,$url); curl_setopt($curl,CURLOPT_RETURNTRANSFER,1); $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 title="点击查看" href="https://www.baidu.com/s?wd='.get_the_title().'" target="_blank" rel="external nofollow noopener noreferrer">百度已收录</a>'; }else { echo '<a style="color: red;" title="一键帮忙提交给百度,谢谢您!" href="https://zhanzhang.baidu.com/sitesubmit/index?sitename='.get_permalink().'" target="_blank" rel="external nofollow noopener noreferrer">百度未收录</a>'; } }
调用方法
将以下代码添加到你想要显示的位置!一般文章模板是single.php,页面模板是page.php。添加好后刷新页面,收录提示能够正常显示就说明ok了。
<?php baidu_record();?>