Wordpress内容页里添加百度熊掌号“搜索结果出图”页面改造代码,在网上找的,已经测试可用。
<?php
//获取文章中的图 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;
}
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>
';}
?>
wordpress修改:
1、cui2.0/function.php 修改评论头像function get_ssl_avatar
2、首页热门4篇文章推荐cui2.0/function.php 手动修改 finction hot_posts_list
3、cui2.0/404.php 修改404页面
4、cui2.0/single.php 修改内容页面
5、首页幻灯片
内容图片大小修改,后台设置-媒体设置 300x200 510x340 900x600 这是适合百度搜索的图片大小
---------
.htaccess的写法,将http转到https 必须按这个去写,不然百度https认证会不通过,下面重写代码已经在“空气净化器网https://www.juxinyou.com”检测成功了,可放心使用。
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# BEGIN WordPress
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# EDN WordPress