首页 > wordPress > 正文
申明:本文章为非原创,作者暂未知,由于建站需要,为网上搜集。实现效果非常不错,实现已经被百度收录的文章显示已收录,未收录的文章显示未收录,点击后可以一键向百度提交链接。

代码及使用方法

打开自己正在使用的主题的文件目录(/wp-content/themes/主题名),找到functions.php。编辑functions.php,在底部加入下面的代码:

/* 检查百度是否已收录文章页面 全体可以见 xcshow---https://www.ydxinzuo.cn 开始*/
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">百度已收录</a>';
} else {
echo '<a style="color: red;" title="一键帮忙提交给百度,谢谢您!" href="https://zhanzhang.baidu.com/sitesubmit/index?sitename='.get_permalink().'" target="_blank" rel="external nofollow noopener">百度未收录</a>';
}
}

上面的代码添加完成后,将<?php baidu_record(); ?>插入到需要显示收录提示的地方,一般文章模板是single.php,页面模板是page.php。添加好后刷新页面,收录提示能够正常显示就说明ok了。

本文章未特殊注明的版权信息归本站所有,著名来源归原作者所有!

猜你喜欢
发表评论

电子邮件地址不会被公开。 必填项已用*标注

评论信息