文章分享到微博的时候就会出现下面的空白图片,检查了一下数据是wp的cdn加速中的文件:
看了下网页的源代码,同样可以找到这个图片。
<meta property="article:published_time" content="2020-03-08T10:40:56+00:00" /> <meta property="article:modified_time" content="2020-03-08T10:43:33+00:00" /> <meta property="og:site_name" content="obaby@mars" /> <meta property="og:image" content="https://s0.wp.com/i/blank.jpg" /> <meta property="og:locale" content="zh_CN" /> <meta name="twitter:creator" content="@ob4by" /> <meta name="twitter:text:title" content="Plist Editor Pro(plist文件编辑工具)V2.5[64 bit] for Windows Crack" /> <meta name="twitter:card" content="summary" /> |
猜测可能是由于wp的社交分享功能导致的,使用jetpack og:image 进行搜索,找到了下面的文章:
https://iblog.ph-wbc.com/jetpack-fb-分享修改-ogimage/
通过文章中的代码即可修改og:image属性, 代码如下(将下面的代码添加到当前主题目录下的functions.php文件末尾即可):
文章分享到微博的时候就会出现下面的空白图片,检查了一下数据是wp的cdn加速中的文件: 看了下网页的源代码,同样可以找到这个图片。 猜测可能是由于wp的社交分享功能导致的,使用jetpack og:image 进行搜索,找到了下面的文章: https://iblog.ph-wbc.com/jetpack-fb-分享修改-ogimage/ 通过文章中的代码即可修改og:image属性, 代码如下: |
function get_feature_image(){ global $post, $posts; $first_img = ''; if ( has_post_thumbnail() ) { $first_img = wp_get_attachment_url( get_post_thumbnail_id() ); } else { ob_start(); ob_end_clean(); $output = preg_match('/< *img[^>]*src *=*["\']?([^"\']*)/i', $post->post_content, $matches); $first_img = $matches[1]; } return $first_img; } function fb_home_image( $tags ) { if ( is_home() || is_front_page() ) { // Remove the default blank image added by Jetpack unset( $tags['og:image'] ); unset( $tags['og:description'] ); //$fb_home_img = get_bloginfo('template_directory').'/img/default.jpg'; $fb_home_image = 'https://h4ck.org.cn/wp-content/uploads//2019/09/logo3.png'; $tags['og:image'] = esc_url( $fb_home_img ); $tags['og:description'] = get_bloginfo('description'); } elseif(is_single( ) ){ unset( $tags['og:image'] ); $tags['og:image'] = get_feature_image(); } return $tags; } add_filter( 'jetpack_open_graph_tags', 'fb_home_image' ); |
修改之后再次分享,图片就可以正常显示了:
原创文章,转载请注明: 转载自 obaby@mars
本文标题: 《jetpack og:image》