<?php
if(is_single()||is_page()){
echo \'<script type="application/ld+json">{
"@context": "https://ziyuan.baidu.com/contexts/cambrian.jsonld",
"@id": "\'.get_the_permalink().\'",
"appid": "这里请填写熊掌号 ID",
"title": "\'.get_the_title().\'",
"images": ["\'.fanly_post_imgs().\'"],
"pubDate": "\'.get_the_time(\'Y-m-d\TH:i:s\').\'"
}</script>
\';}
//获取文章中的图 last update 2018/01/22
function fanly_post_imgs(){
global $post;
$src = \'\';
$content = $post->post_content;
preg_match_all(\'/<img .*?src=[\"|\\'](.+?)[\"|\\'].*?>/\', $content, $strResult, PREG_PATTERN_ORDER);
$n = count($strResult[1]);
if($n >= 3){
$src = $strResult[1][0].\'","\'.$strResult[1][1].\'","\'.$strResult[1][2];
}elseif($n >= 1){
$src = $strResult[1][0];
}
return $src;
}
?>
这段代码放在主题的header.php文件的</head>标签之前,设置APPID即可。
需要注意的是:
图片尺寸比例3:2,图片大小不得低于300*200px;
图片必须出现在文章正文中,且按顺序自动提取图片;
同一个网页中,图片不能重复;
图片内容不得低俗,不能出现二维码、电话、微信号等受益方式;