纯代码实现为子比主题添加百度是否收录功能的教程

最近在群里看到小伙们都想要在文章中添加百度是否收录功能,于是百度了一下代码,然后就添加到子比主题中了。这代码感觉没啥用,百度收没收录的文章它都显示已收录!!!仅供参考吧。

美化教程:

本文修改之处只适用于子比zibill主题,其它主题请自行寻找修改处!

1、打开 /zibll/inc/functions/functions.php 在最后面添加以下代码:

/**
 * WordPress 添加百度是否收录功能
**/
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="http://www.baidu.com/s?wd='.get_the_title().'"><i class="fa fa-paw fa-lx"></i> 百度已收录</a>';
   } else {
        echo '<a style="color:red;" rel="external nofollow" title="点击提交,谢谢您!" target="_blank" href="http://zhanzhang.baidu.com/sitesubmit/index?sitename='.get_permalink().'"><i class="fa fa-paw fa-lx"></i> 百度未收录</a>';
   }
}

2、打开 /zibll/inc/functions/zib-single.php 搜索 在这其下一行添加以下代码:

<?php baidu_record(); ?>  

由于没啥实际的意义,本站已经去掉了,喜欢的可以设置使用。

版权声明:本文由 鹿泽笔记 原创发布。

本文链接:https://www.bailuze.com/8643.html

许可协议:本文标题《纯代码实现为子比主题添加百度是否收录功能的教程》,转载请注明文章出处及原始链接。

鹿泽
鹿泽

深耕 SEO优化 十二年,从个人博客爱好者到专业谷歌优化顾问的成长之路。技术派SEO、全域流量技术运营专家,拥有多年从业经验,热衷于分析算法逻辑与推理的精准匹配。