wordpress自带的PING服务能在发表新文章时,主动告知站点更新服务。除去这类方法告知百度进行抓取,还能通过百度供给的链接提交API进行推送。
详情见:https://ziyuan.baidu.com/linksubmit/index
百度的链接主动提交能使用API、JS、sitemap等方法。因而伏笔VPS就想着直接在正题的functions.php增加这个功能。
规律很简单,当新文章推送时(包罗更新),通过CURL访问百度提交链接的API便可。主要用到了wordpress的publish_post钩子
上代码: 注意:token改成伏笔VPS的
function push_to_baidu($ID) { //获得文章的链接 $permalink = get_permalink($ID); $api = 'http://data.zz.baidu.com/urls?site=bugxia.com&token=百度链接提交API的TOKEN'; $ch = curl_init(); $options = array( CURLOPT_URL => $api, CURLOPT_POST => true, CURLOPT_RETURNTRANSFER => true, CURLOPT_POSTFIELDS => $permalink, CURLOPT_HTTPHEADER => array('Content-Type: text/plain'), ); curl_setopt_array($ch, $options); $result = curl_exec($ch); //下面这一行是写日记到正题目录,可选 //file_put_contents(dirname(__FILE__)."/pushLog.txt",$result."\n",FILE_APPEND); } add_action('publish_post', 'push_to_baidu');
以上代码增加到正题的functions.php,每回推送、更新文章时便可自动提交文章的链接给百度,告知百度的蜘蛛前来抓取。
原文链接:https://vps.fubi.hk/foreshadowingvps/zhishiku/20181025/6222.html