有没有办法!当点击Facebook上的分享按钮时,图片应该是帖子标题和描述的顶部,而不是留在Facebook分享窗口中。试图自定义Facebook分享按钮
我曾试图将该代码作为一个WordPress插件
add_image_size('fb-preview', 190, 190, true);
// get image preview
function ST4_get_FB_image($post_ID){
$post_thumbnail_id = get_post_thumbnail_id($post_ID);
if ($post_thumbnail_id){
$post_thumbnail_img = wp_get_attachment_image_src($post_thumbnail_id, 'fb-preview');
return $post_thumbnail_img[0];
}
}
// get post description
function ST4_get_FB_description($post){
if ($post->post_excerpt){
return $post->post_excerpt;
} else {
// post excerpt is not set, we'll take first 55 words from post content
$excerpt_length = 55;
// clean post content
$text = str_replace("\r\n"," ", strip_tags(strip_shortcodes($post->post_content)));
$words = explode(' ', $text, $excerpt_length + 1);
if (count($words) > $excerpt_length) {
array_pop($words);
$excerpt = implode(' ', $words);
return $excerpt;
}
}
}
function ST4FB_header(){
global $post;
$post_featured_image = ST4_get_FB_image($post->ID);
$post_description = ST4_get_FB_description($post);
if ((is_single()) AND ($post_featured_image) AND ($post_description)){
?>
<link rel="image_src" href="<?php echo $post_featured_image; ?>" />
<meta name="title" content="<?php echo $post->post_title; ?>" />
<meta name="description" content="<?php echo $post_description; ?>" />
<?php
}
}
add_action('wp_head','ST4FB_header');
和Facebook上分享按钮后的网页上。 );
ID)); ?> & t = post_title); ?>“>在Facebook上分享
你不会用Facebook对话框搞砸 – ceejayoz