如果您访问此页面:http://www.leicesterymca.co.uk/show/?showid=3ea8f5c1-55f7-e611-80d7-00505601004c并点击Facebook图标共享该节目,您将看到它所拍摄的图像是我网站的徽标。我希望它能拍摄我的主要展示图像。
我知道它不会这样做,因为主要的展示图像不是特色图像,而是从XML源中提取的图像。
我必须从XML源中提取此图像的代码如下:
<div class="featured-image-show"><img src='<?php echo $show_img_url ?>' /></div>
我已经为我的Wordpress函数文件找到了以下代码,当我使用共享按钮共享页面时添加显示页面精选图像...
//Adding the Open Graph in the Language Attributes
function add_opengraph_doctype( $output ) {
return $output . ' xmlns:og="http://opengraphprotocol.org/schema/" xmlns:fb="http://www.facebook.com/2008/fbml"';
}
add_filter('language_attributes', 'add_opengraph_doctype');
//Lets add Open Graph Meta Info
function insert_fb_in_head() {
global $post;
if ( !is_singular()) //if it is not a post or a page
return;
echo '<meta property="fb:admins" content="YOUR USER ID"/>';
echo '<meta property="og:title" content="' . get_the_title() . '"/>';
echo '<meta property="og:type" content="article"/>';
echo '<meta property="og:url" content="' . get_permalink() . '"/>';
echo '<meta property="og:site_name" content="http://www.leicesterymca.co.uk"/>';
if(!has_post_thumbnail( $post->ID )) { //the post does not have featured image, use a default image
$default_image="http://example.com/image.jpg"; //replace this with a default image on your server or an image in your media library
echo '<meta property="og:image" content="' . $default_image . '"/>';
}
else{
$thumbnail_src = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'medium' );
echo '<meta property="og:image" content="' . esc_attr( $thumbnail_src[0] ) . '"/>';
}
echo "
";
}
add_action( 'wp_head', 'insert_fb_in_head', 5 );
目前我假设这会查找精选图片并分享,如果它没有找到特色图片,则默认为我可以指定的图像。
所以我的问题是:我如何指定它来显示我在代码中的图像而不是特色图像甚至徽标......
<div class="featured-image-show"><img src='<?php echo $show_img_url ?>' /></div>