Search code examples
facebookwordpresssharethis

FB Share this link doesn't fetch post desc and thumb


On a wordpress site, I'm using sharethis plugin...

http://support.sharethis.com/customer/portal/articles/446440-wordpress-integration

Where FB Share Link Button doesn't fetch and display Post description & image on facebook.

Any idea/hint what could be wrong?


Solution

  • Please add this function into your functions.php file.

    function wpc_fb_opengraph() {
    $wpc_image_url = wp_get_attachment_image_src( get_post_thumbnail_id(), 'large');
    ?>
    <meta property="og:title" content="<?php the_title(); ?>" />
    <meta property="og:url" content="<?php the_permalink(); ?>" />
    <meta property="og:site_name" content="<?php bloginfo('name'); ?>" />
    <meta property="og:description" content="<?php echo strip_tags(get_the_excerpt($post->ID)); ?>" />
    <meta property="fb:app_id" content="APP ID HERE">
    <meta property="fb:admins" content="YOUR FB USER ID (OR USERNAME) HERE"/>
    <meta property="og:image" content="<?php echo $wpc_image_url[0] ?>"/>
    <?php }
    
    add_action('wp_head', 'wpc_fb_opengraph');
    

    Note : if you haven't yet any facebook app for your web pages you dont have to use this lines .

    <meta property="fb:app_id" content="APP ID HERE">
    <meta property="fb:admins" content="YOUR FB USER ID (OR USERNAME) HERE"/>
    

    Happy Wordpress..