【问题标题】:trying to customize the facebook share button尝试自定义 Facebook 分享按钮
【发布时间】:2013-11-27 12:31:51
【问题描述】:

有办法吗!当点击帖子中的 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 对话感到厌烦。

标签: facebook wordpress


【解决方案1】:

我建议阅读 facebook api 文档,并保持他们不希望你弄乱他们的东西的心态。

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

即使没有这种心态,这里的一切都表明您无法控制这一点,如果您这样做,这是一个 fb 想要修复的未被发现的错误(因此会破坏您发现的任何内容)。

【讨论】:

    猜你喜欢
    • 2014-03-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多