代码及使用方法
打开自己正在使用的主题的文件目录(/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 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了。
常见问题FAQ
- 免费下载或者VIP会员专享资源能否直接商用?
- 本站所有资源版权均属于原作者所有,这里所提供资源均只能用于参考学习用,请勿直接商用。若由于商用引起版权纠纷,一切责任均由使用者承担。更多说明请参考 VIP介绍。
- 提示下载完但解压或打开不了?
- 找不到素材资源介绍文章里的示例图片?
- HELLO资源网