Wordpress内容页里添加百度熊掌号“搜索结果出图”页面改造代码

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值