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
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.xxx.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^xxx.com [NC]
RewriteRule ^(.*)$ https://www.xxx.com/$1 [L,R=301]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress