
WordpPress 后台搜索安装并启用 AMP 插件后,插件会自动为文章页创建一个 AMP 文章页面,页面链接 URL 是在原页面的链接 URL 加上“?amp”,文章页面链接 URL 是在原页面的链接 URL 加上“/amp”
共用 AMP robots.txt
User-agent: baiduspider
Allow: /amp
Allow: ?amp
User-agent: googlebot-mobile
Allow: /amp
Allow: ?amp
User-agent: *
Disallow: /amp
Disallow: ?amp
百度 MIP 谷歌 AMP robots.txt
User-agent: baiduspider
Allow: /mip
Allow: ?mip
User-agent: googlebot-mobile
Allow: /amp
Allow: ?amp
User-agent: *
Disallow: /mip
Disallow: ?mip
Disallow: /amp
Disallow: ?amp
主动推送提交AMP页面 functions.php
/**
* @date 2018-03-07 10:12:38
*/
if(!function_exists(‘Baidu_amp’)){
function Baidu_amp($post_ID) {
//已成功推送的文章不再推送
if(get_post_meta($post_ID,’Baiduamp’,true) == 1) return;
$url = get_permalink($post_ID);
if(get_post_type($post_ID)==’page’){
$url=$url.’?amp’;
}
if(get_post_type($post_ID)==’post’){
$url=$url.’/amp/’;
}
$api = ‘http://data.zz.baidu.com/urls?site=网站首页地址&token=密钥&type=amp’;
//登录百度搜索资源平台 >> 网站支持 >> 数据引入 >> MIP& >> AMP 下方的数据提交就能看到 AMP 推送接口调用地址
$request = new WP_Http;
$result = $request->request( $api , array( ‘method’ => ‘POST’, ‘body’ => $url , ‘headers’ => ‘Content-Type: text/plain’) );
$result = json_decode($result[‘body’],true);
//如果推送成功则在文章新增自定义栏目 Baiduamp,值为 1
if (array_key_exists(‘success_amp’,$result)) {
add_post_meta($post_ID, ‘Baiduamp’, 1, true);
}
}
add_action(‘publish_post’, ‘Baidu_amp’, 0);
}
人吐槽 | 人点赞 |
发表评论