2013-11-27 137 views
0

有没有办法!当点击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上分享enter image description here

+0

你不会用Facebook对话框搞砸 – ceejayoz

回答

1

我建议阅读Facebook的API文档,并采取心态,他们不希望你乱用他们的东西。

https://developers.facebook.com/docs/reference/dialogs/feed/

即使没有这种心态这里的一切都表明你无法控制这一点,如果你这样做的话,这是一个未发现的错误,fb想要修复(并因此破坏你找到的任何东西)

+0

谢谢我虽然可能有可能,但现在我清楚了。 – Ask4Tec