wordpress使用BingWebmaster提交API

 

一,生成 API 密钥

先登陆https://www.bing.com/webmasters/,点右上角的“齿轮”图标。
展开之后点“API 访问”,再点“API 密钥”,创建一个,完成之后可以点右边的复制图标。

二,代码

加到你主题的functions.php里边即可。

function bd_post_json($urls, $api, $httpheard ) {
	$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);
	curl_close($ch);
}

function bd_bing_api( $post_ID, $post, $update ) {
	if ( wp_is_post_revision( $post_ID ) || wp_is_post_autosave( $post_ID ) ) {
		return;
	}
	if ( 'publish' === $post->post_status ) {
		if ( 'post' === $post->post_type ) {
			$urls = '{ "siteUrl":"'.get_bloginfo('url').'","url":"'.get_permalink( $post ).'" }';
			$api = 'https://ssl.bing.com/webmaster/api.svc/json/SubmitUrl?apikey=呢度填你刚申请的API-KEY';
			$httpheard = array('Content-Type: application/json', 'charset=utf-8');
			bd_post_json( $urls, $api, $httpheard );
		}
	}
}
add_action( 'save_post', 'bd_bing_api', 10, 3 );
本文发布于 。属于 WordPress点滴 分类,被贴了 标签。

《wordpress使用BingWebmaster提交API》有0个评分

★★★★★
★★★★
★★★
★★
0
0
0
0
0

wordpress使用BingWebmaster提交API》有1个想法

发表回复

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