【发布时间】:2016-08-21 23:25:57
【问题描述】:
我正在使用以下功能,并且在我确定有特色图片集的页面上使用 FB 的调试器:
function fb_opengraph() {
global $post;
if(is_page()) {
if(has_post_thumbnail($post->ID)) {
$img_src = wp_get_attachment_image_src(get_post_thumbnail_id( $post->ID ), 'medium');
} else {
$img_src = get_stylesheet_directory_uri() . '/img/opengraph_image.jpg';
}
if($excerpt = $post->post_excerpt) {
$excerpt = strip_tags($post->post_excerpt);
$excerpt = str_replace("", "'", $excerpt);
} else {
$excerpt = get_bloginfo('description');
}
?>
<meta property="og:title" content="<?php echo the_title(); ?>"/>
<meta property="og:description" content="<?php the_content(); ?>"/>
<meta property="og:type" content="article"/>
<meta property="og:url" content="<?php echo the_permalink(); ?>"/>
<meta property="og:site_name" content="<?php echo get_bloginfo(); ?>"/>
<meta property="og:image" content="<?php echo $img_src; ?>"/>
<?php
} else {
return;
}
}
add_action('wp_head', 'fb_opengraph', 5);
当前发生的情况是 $img_src 返回值为“Array”,而不是该页面的特色图像的 URL。我不确定这个“数组”值是从哪里来的,但更重要的是我试图在没有运气的情况下提取特色图片 URL。
有什么想法吗?谢谢!
【问题讨论】:
标签: wordpress facebook-opengraph