wordpress站点加速bing雅虎等国外搜索引擎收录代码

微信扫一扫,分享到朋友圈

wordpress站点加速bing雅虎等国外搜索引擎收录代码
收藏 00

代码

将以下代码复制到主题 functions文件:

//WordPress IndexNow
add_action('save_post','fanly_indexnow',10,3);
function fanly_indexnow($post_id, $post, $update){
    if($post->post_status!='publish') return;
    $key = '90cf913328b64b2eb6115994599e7788';
    $api = 'https://api.indexnow.org/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]
        ])
    ]);
}

说明

$key: 8 – 128 个十六进制字符。密钥只能包含以下字符:小写字母(a-z),大写字母(A-Z),数字(0-9),以及短破折号(-)。

$api:https://api.indexnow.org/indexnow 或 https://www.bing.com/indexnow 或 https://yandex.com/indexnow 三选一,推荐第一个或第二个。获取key的方法

以上代码中$key 和$api 的值是可以修改的,同时$key 的值放置在当前网站根目录需要放置同名 txt 文件,例如:$key =4fe21022a6554c5ca88ee4beb621f9f4;那么需要建立一个4fe21022a6554c5ca88ee4beb621f9f4.txt 文件,且 txt 文件内容也为 4fe21022a6554c5ca88ee4beb621f9f4,放置在网站根目录。

IndexNow.org

一个热爱互联网的咸鱼
上一篇

WordPress B2主题火车头发布模块字段说明[b2主题火车头发布模块下载]

你也可能喜欢

发表评论

您的电子邮件地址不会被公开。 必填项已用 * 标注

提示:点击验证后方可评论!

插入图片

热门

    抱歉,30天内未发布文章!
返回顶部