wordpress代码检测当前页面百度是否收录
以下代码由PHP站长网 52php.cn收集自互联网现在PHP站长网小编把它分享给大家,仅供参考 作为 wordpress 站长,一定遇到过发布了许多文章而百度没有收录的情况,或者已经收录了,还需要你去单独查看该文章是否被百度收录,很是麻烦,对于新上线网站总会去查询网页收录了多少,哪些还没收录。这个功能实用性极佳。 方法一下面只需一段代码即可随时了解百度收录情况,并提供提交百度入口,以加速百度收录。 //百度收录提示 if(git_get_option('git_baidurecord_b') && function_exists('curl_init')): function baidu_check($url) { global $wpdb; $post_id = (null === $post_id) ? get_the_ID() : $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,'没有找到')) { if ($baidu_record == 0) { update_post_meta($post_id,1); } else { add_post_meta($post_id,1,true); } return 1; } else { if ($baidu_record == false) { add_post_meta($post_id,true); } return 0; } } else { return 1; } } 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" data-original-title="点击查看">已收录</a>'; } else { echo '<a color: red;" title="" href="http://zhanzhang.baidu.com/sitesubmit/index?sitename=' . get_permalink() . '" target="_blank" rel="external nofollow" data-original-title="点击提交,谢谢您!">未收录</a>'; } } endif; 上面的函数式放在主题 functions 文件中,然后在文章内容页面适合地方加入下方这段代码 <?php if (git_get_option('git_baidurecord_b') && function_exists('curl_init')) { ?><span class="muted"><i class="fa fa-flag"></i> <?php baidu_record(); ?></span> 方法二只有管理员才能在站台看到该文章是否被百度收录的提示,其它的访客是完全看不到的,而且本代码有自动的未收录提示功能,如果我们点击未收录提示字样,可以直接链接到提交百度站长链接的页面,主动向百度提交我们未被收录的文章链接,而且操作成本也很低,只需要把以下的代码复制到我们当前的 wordpress 主题文件夹的 functions.php 文章中,即可实现: /* 检查百度是否已收录文章页面 管理员可以见 */ function d4v($url){ $url='http://www.baidu.com/s?wd='.$url; $curl=curl_init(); curl_setopt($curl,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) echo '<p align=right><b><a target="_blank" title="点击查看" rel="external nofollow" href="https://www.baidu.com/s?wd='.get_the_title().'">此文章已被百度收录</a></b>(仅管理员可见)</p>'; else $content="<p align=right><b><a color:red target=_blank href=https://zhanzhang.baidu.com/sitesubmit/index?sitename=".get_permalink().">百度未收录!点击此处一键提给百度交</a></b>(仅管理员可见)</p>".$content; return $content; } /* 检查百度是否已收录文章页面 管理员可以见 */ 以上内容由PHP站长网【52php.cn】收集整理供大家参考研究如果以上内容对您有帮助,欢迎收藏、点赞、推荐、分享。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |