欢迎光临
我们一直在努力

WordPress百度收录代码

1.在Wordpress下编辑functions.php文件在“?>”之前添加如下代码

//添加百度是否收录功能
function baidu_check($url, $post_id){
  $baidu_record  = get_post_meta($post_id,'baidu_record',true);
  if( $baidu_record != 1){
    $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,'没有找到该URL。您可以直接访问') && !strpos($rs,'很抱歉,没有找到与') ){
      update_post_meta($post_id, 'baidu_record', 1) || add_post_meta($post_id, 'baidu_record', 1, true);
      return 1;
    } else {
      return 0;
    }
  } else {
     return 1;
  }
}
function baidu_record() {
  global $wpdb;
  $post_id = ( null === $post_id ) ? get_the_ID() : $post_id;
  if(baidu_check(get_permalink($post_id), $post_id ) == 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>';
 }
}

2.然后在需要在Wordpress显示的地方添加如下代码

<span class="item"><?php baidu_record(); ?></span>

 

窗外天空
关注公众号『窗外天空』

获取更多建站运营运维新知!
互联网创业、前沿技术......

赞(0) 打赏
文章名称:《WordPress百度收录代码》
文章链接:https://www.nixonli.com/22898.html
本站资源仅供个人学习交流,请于下载后24小时内删除,不允许用于商业用途,否则法律问题自行承担。

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

觉得文章有用就打赏一下文章作者

非常感谢你的打赏,我们将继续给力更多优质内容,让我们一起创建更加美好的网络世界!

支付宝扫一扫打赏

微信扫一扫打赏