WordPress.org

Forums

[resolved] feature image can not share on facebook in single.php (7 posts)

  1. Nimesh
    Member
    Posted 11 months ago #

    Hello all,
    I want to share post feature image in my facebook account.
    For that I have use the facebook share button code.
    It will working fine with my one template page, but as I have use this code in single.php, it could not work, I can not identify the reason.
    I have use the code in my single.php file like:

    //header
    <div id="fb-root"></div>
    <script>(function(d, s, id) {
              var js, fjs = d.getElementsByTagName(s)[0];
              if (d.getElementById(id)) return;
              js = d.createElement(s); js.id = id;
              js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1&appId=196109523902137&version=v2.0";
              fjs.parentNode.insertBefore(js, fjs);
            }(document, 'script', 'facebook-jssdk'));</script>
    
    //to get feature image url
    $url = wp_get_attachment_url( get_post_thumbnail_id($_GET['id']) );
    
    $share_url  =  get_permalink(get_the_ID());
    
    <a id="ref_fb"  href="http://www.facebook.com/sharer.php?s=100&p[title]=<?php echo $title;?>&p[summary]=<?php echo $description;?>&p[url]=<?php echo urlencode($share_url);?>&
    p[images][0]=<?php $url;?>" onclick="javascript:window.open(this.href, '', 'menubar=no,toolbar=no,resizable=no,scrollbars=no,height=400,width=600'); return false;">
    <img src="<?php bloginfo('template_url')?>/_images/fb.png" alt=""/></a>

    i have share the posr succefully but can not see the feature image.
    you can test/see from this url:
    http://www.novelwall.org/dev/cv-builder-overview-post1/?id=956&&tabName=content-1&&page=jobs
    I have also echo the url in above code but :-(

    Any help will be apreacialble. thank you.

  2. sunrader
    Member
    Posted 11 months ago #

    I would use a plugin that controls the open graph information sent to Facebook. I use WP Open Graph. Works well. Use FB debugger to make sure you are getting what you want.

    http://wordpress.org/plugins/wp-open-graph/

  3. Nimesh
    Member
    Posted 11 months ago #

    sunrader, I think in my code there no need to use this plugin bcause all other think working fine also working in other template fine, the only issue with this single.php and anohter think I have use the facebook debuger tool and I get the one warning in image like,
    "og:image could not be downloaded or is too small"
    So accroding to that warning, I have add the big image of at least 200x200px
    but even can not get proper image.

  4. Nimesh
    Member
    Posted 11 months ago #

    other thinks that i have notice in facebook debuger,
    I could see the "When shared, this is what will be included" in this portion I could see the feature image very well but not from my page.

    I have also notice that feature image has been displayed in given below portion of my debuger screen:
    "Based on the raw tags, we constructed the following Open Graph properties" in og:image as.

    Also notice "These are the raw tags that we found" the found meta tag as
    <meta property="og:image" content="http://www.novelwall.org/dev/wp-content/uploads/2014/03/big_Novelwall_pdf_gray_design-300x300.jpg" />

    Or you can see this also info directly from,
    https://developers.facebook.com/tools/debug/og/object/
    filling the url like: http://www.novelwall.org/dev/bussiness-opportunities-client-success-post1/?id=1001&&tabName=content-1&&page=solu

  5. sunrader
    Member
    Posted 11 months ago #

    Of course don't use it if you don't think it's needed, but on mine this plugin forces FB to get the right information and is easy to use.

  6. Nimesh
    Member
    Posted 11 months ago #

    You are right, I have just install the this plugin and it display data that will be displayed on share popup, yes here I can see the right snippet that display the right feature image. but not from my front side.

  7. Nimesh
    Member
    Posted 10 months ago #

    Hi,
    Finally I have solve this problem myself.
    there is a problem with share url. It has been not take the full url usinge the code,

    $url = wp_get_attachment_url( get_post_thumbnail_id($_GET['id']) );

    So I have to put the code like:

    function curPageURL()
    {
            $pageURL = 'http';
            if ($_SERVER["HTTPS"] == "on")
            {
                    $pageURL .= "s";
            }
            $pageURL .= "://";
            if ($_SERVER["SERVER_PORT"] != "80")
            {
                    $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
            }
            else
            {
                    $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
            }
            return $pageURL;
    }
    $url =  curPageURL();

Reply

You must log in to post.

About this Topic