Yoast.com actually covered this quite recently…
if ( is_singular() ) {
global $post;
if ( current_theme_supports('post-thumbnails')
&& has_post_thumbnail( $post->ID ) ) {
$thumbnail = wp_get_attachment_image_src(
get_post_thumbnail_id( $post->ID ), 'thumbnail', false);
echo '<meta property="og:image"
content="'.$thumbnail[0].'" />';
}
echo '<meta property="og:title"
content="'.get_the_title().'" />';
if ( get_the_excerpt() != '' )
echo '<meta property="og:description"
content="'.strip_tags( get_the_excerpt() ).'" />';
}
Explanation and more details are here: http://yoast.com/facebook-share-wordpress/
Related Posts:
- Set Custom Post feature image as og:image
- WordPress Facebook Open Graph plugin not working for 1 specific image [closed]
- How can you upload an image from within a settings page?
- WordPress Post featured image URL in the header
- Sharing images to social media – issue with aspect ratio
- Is there a way to add a featured image to an image/file attachment page?
- How to make Facebook share the featuterd image from url on WordPress
- Tried everything but Facebook share button won’t load the post thumbnail
- Filter to remove image dimension attributes?
- Stop wordpress from hardcoding img width and height attributes
- how to get original image using wp_get_attachment_image_src
- WordPress adding scaled images that don’t exist (1536×1536 and 2048×2048)
- Add new image size to media uploader so users can insert into post?
- How to insert pictures without hard coded dimensions?
- How to modify image editor dialog options on WordPress?
- Is there a hook which fires after all thumbnails are generated?
- Auto Add Image Title,Caption,Alt Text,Description while uploading Images in WordPress
- How to have different captions for same image, for galleries?
- Using Images in WordPress – Best Practices
- WP 3.5 and Galleries – how to count images?
- Is there a filter to define the OG image on a given post?
- Image Scaling using get_the_post_thumbnail issue in WordPress
- Prevent large image uploads
- Modifying an uploaded image with ‘wp_get_image_editor’ and ‘wp_handle_upload_prefilter’
- How do I delete all generated images from my server except those currently used in posts
- How to create thumbnails with a fixed width, so all of them will have the same width?
- WordPress is Inserting images into Post as HTTP and not HTTPS
- Change the output for [gallery] shortcode
- “There has been an error cropping your image” when cropping image
- Downsizing Many Large Images Attached to Posts, in Bulk?
- Apply image width to tag
- Excludes posts that don’t have attachments in the_content()
- Remove duplicate images from media library.
- WordPress Image Editor doesn’t update thumbs specified with `add_image_size()`
- Extract image src from a post and send it to an external form
- Get an image from url in front end submission form
- Can images be automatically compressed?
- Adding custom image size to the media image editor
- Disabling auto-resizing of uploaded images
- How do I delete thousands of unattached images?
- Wrong domain in uploads folder
- How can i alter the amount of different images sizes being stored?
- How to force WordPress to add new images at the beginning of the gallery?
- Why would image paths in wordpress suddenly change?
- Add visual editor to Media Edit Screen
- Re-process Images
- Show prev and next post links for parent post of current image in attachment page?
- could not upload image in media library
- How to set the width and height rule for featured image
- Passing srcset to image attachment method
- Why is wordpress searching for @2x images?
- Check if page/post has any anchors that link to an image jpg/gif/png
- Broken urls with http site and https wp-admin
- Image File Names
- Images in upload folder with hexadecimal names
- How to check if user is uploading/setting an image as a featured image?
- hardcrop images in gutenberg “latest posts” block
- Open graph problem: Showing wrong description of homepage while sharing on Facebook [closed]
- JavaScript and images files are not recognized
- Get uploaded image path in wordpress by filename
- How to extract image width from add_image_size?
- Link to full size image or attachment page in photo theme
- Use Gravatar as fallback image if no local image is not found
- add the post as canonical for attachment page wordpress
- How to get image ID to use inside wp_read_image_metadata()?
- Retrieving an alt tag from a custom field
- Exclude featured image from gallery in wp-admin
- Conditionally add apt. Open Graph meta data to different pages on WordPress site
- Large size image breaks template layout
- How to remove Geo Tagging on image uploads, but not other EXIF data?
- Trying to create a mouseover effect in html using Gutenberg editor
- Replace original image, WP image editor
- How to output images as figure/figcaption
- Make Images appear in the same order as in media browser using get children?
- wordpress get gallery images title
- How to wrap normal image tag with figure HTML5 element
- How to fix “.webp” being auto-added to the end of image urls
- Customizing the attachement page to show rest of all images in a gallery from post
- Disable all resizing and compression
- Update old Post image metadata to ‘thumbnail’ wp_attached_file
- How to find images in lazyload to set alt attribute?
- having issue while uploading An error occured in the upload. Please try again later
- How to change image atributes right before an image to be saved?
- Is it possible to change ‘Link to’ in all images in all articles?
- Control Responsive Images
- Is it possible to put images as url in document [closed]
- Creating ‘required’ fields in the ‘add media’ window
- Importing images results to wrong folder structure
- WP keeps looking up post thumbnail on https even though wp-config says http
- How to post a mosaic of an image gallery instead of the entire gallery inside a post’ [closed]
- How to add an image to the post preview in the free theme “food recipes”
- I am getting useless alphabets in images link
- How to replace images?
- How can I echo og:video url, if the post has video content?
- using media_sideload_image with a file from theme directory
- Facebook preview Open Graph Object Debugger
- wp_get_attachment_image_src() returning incorrect width and height [duplicate]
- Blank upload.php page
- The alt=”” attribute is empty
- Add custom text in the media library image meta area