WordPress添加判断当前文章是否被百度收录

PHP代码

把以下代码添加到当前主题function.php文件中

/*判断当前文章是否被百度收录*/
function d4v($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;
    }
}
add_filter( 'the_content',  'baidu_submit' );
function baidu_submit( $content ) {
if( is_single() && current_user_can( 'manage_options') )
if(d4v(get_permalink()) == 1)
            $content="<center>百度已收录</center>".$content;
else
            $content="<p align=right><b><center><a style=color:red target=_blank href=http://zhanzhang.baidu.com/sitesubmit/index?sitename=".get_permalink().">百度未收录!点击提交</a></center></b></p>".$content;
return $content;
    }

使用说明

PS:此状态只会在管理员登录后才能看到,显示位置在当前文章中

原文网址:www.5che2.com

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

给TA打赏
共{{data.count}}人
人已打赏
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索