如今互聯(lián)網(wǎng)的信息是比較多的,我們?cè)诎l(fā)布文章之后最好主動(dòng)推送至各大搜索引擎,我們熟悉的百度搜索就有主動(dòng)推送提交工具,有很多的主題和插件就可以實(shí)現(xiàn)。當(dāng)然,互聯(lián)網(wǎng)不只有百度搜索引擎,還有必應(yīng)等搜索引擎,這里,如果我們需要主動(dòng)提交必應(yīng),提高搜索引擎爬蟲(chóng)抓???
當(dāng)然,我們可以通過(guò) Bing URL Submissions Plugin 插件實(shí)現(xiàn)插件的自動(dòng)推送,這里我們?nèi)绻幌胗貌寮?,也可以直接用剝離的代碼實(shí)現(xiàn)。
//API推送給必應(yīng) function bd_bing_api( $post_ID, $post, $update ) { if ( wp_is_post_revision( $post_ID ) || wp_is_post_autosave( $post_ID ) ) { return; } if(get_post_meta($post_ID,'Bingsubmit',true) == 1) return; if ( 'publish' === $post->post_status ) { if ( 'post' === $post->post_type ) { $urls = '{ "siteUrl":"你的網(wǎng)站域名","url":"'.get_permalink($post_ID).'" }'; $api = 'https://ssl.bing.com/webmaster/api.svc/json/SubmitUrl?apikey=你申請(qǐng)的API'; $httpheard = array('Content-Type: application/json', 'charset=utf-8'); $ch = curl_init(); $options = array( CURLOPT_URL => $api, CURLOPT_POST => true, CURLOPT_RETURNTRANSFER => true, CURLOPT_POSTFIELDS => $urls, CURLOPT_HTTPHEADER => $httpheard, ); curl_setopt_array($ch, $options); $result = curl_exec($ch); add_post_meta($post_ID, 'Bingsubmit', 1, true); curl_close($ch); } } } add_action( 'save_post', 'bd_bing_api', 10, 3 );
如上代碼,我們只需要在兩處修改自己的網(wǎng)站域名和API信息,然后貼到當(dāng)前主題的 Functions.php 文件中,在編輯文件發(fā)布就可以自動(dòng)實(shí)現(xiàn)提交到必應(yīng)搜索引擎提高加速索引收錄。
API 信息的獲?。?/strong>
如上圖在右上角設(shè)置圖標(biāo)中找到 「API訪問(wèn)」。
然后看到 「API密鑰」如果沒(méi)有生成,我們生成一個(gè)即可,然后復(fù)制到對(duì)應(yīng)的代碼中提交。對(duì)于網(wǎng)站URL,我們需要是完成的URL,包括HTTPS或HTTP的。
評(píng)論