简体   繁体   中英

Add Dynamic Post Link To Facebook With Post Thumbnail

I'm using this code from the official FB Developer page

<div class="fb-share-button" data-href="https://developers.facebook.com/docs/plugins/" data-layout="button_count" data-size="small"><a target="_blank" href="https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fdevelopers.facebook.com%2Fdocs%2Fplugins%2F&amp;src=sdkpreparse" class="fb-xfbml-parse-ignore">Share</a></div>

But it's hard coded 1 URL. I need to add get_permalink() for the post URL and get_the_post_thumbnail_url() for the featured image but not sure how to do this in PHP.

I can work out the data-href using get_permalink() but can't get the post thumbnail working.

I did output the ig tabs within the head tags like this

printf( '<meta property="og:url" content="%s" />', get_permalink() );

printf( '<meta property="og:image" content="%s" />', get_the_post_thumbnail_url( get_the_ID(), 'full' ) );

When i use this code it works but it doesn't include the image

'<div class="fb-share-button" data-layout="button_count" data-size="large"></div>';

Is there a way to add the single post URL and featured image in PHP using sprintf?

Works, the only problem was when using local it doesn't.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM