如果我們用過 IndexNow Plugin 插件的話應該知道在Bing搜索引擎工具中有這個插件可以提高必應和幾個搜索引擎的抓取的,當然也不是所有的搜索引擎都識別。如果我們有需要做必應搜索推送的可以配合這個插件,當然我們也可以不用插件直接用代碼實現(xiàn)。
//NoPlugin IndexNow add_action('save_post','noplugin_indexnow',10,3); function noplugin_indexnow($post_id, $post, $update){ if ( wp_is_post_revision( $post_id ) || wp_is_post_autosave( $post_id ) ) { return; } if($post->post_status != 'publish'){ return; } if (get_post_meta($post_id, 'apipush', true) == "0") { return; } $key = '自己獲取KEY'; $api = 'https://www.bing.com/indexnow'; $url = get_permalink($post_id); wp_remote_post( add_query_arg( ['url'=>$url,'key'=>$key], $api ), [ 'headers' => ['Content-Type'=>'application/json; charset=utf-8'], 'timeout' => 10, 'sslverify' => false, 'blocking' => true, 'body' => json_encode([ 'host' => parse_url($url)['host'], 'key' => $key, 'urlList' => [$url] ]) ]); update_post_meta($post_id, "apipush", "0"); }
這里我們需要打開 :https://www.bing.com/indexnow/getstarted
然后看到這里。
這里我們獲取KEY文件然后制作成對應的文件txt,丟到網(wǎng)站根目錄后,然后再替換上面的代碼 Key 后保存到我們的 Functions.php 中。
這里無插件可以替換成之前用過的 IndexNow 插件。
評論