If you are using WordPress post thumbnails, you can use Facebook Open Graph Meta Data plugin by Paulund but Thesis theme for WordPress offers more than just post thumbnails and if you are using Thesis Thumbnails for WordPress (As we use it on my Indian Recipe Blog), it does not make sense to edit each post to add WordPress thumbnail for your post rather it is better to be using a code that can use Thesis Thumbnails and add the required open graph tags for Facebook.
I found the plugin code simple to edit and you can also see the same here. Using the above code as reference I added the option to use the Thesis Thumbnails for Open Graph tags. I also removed the code to fetch post excerpt from content and is using get_the_excerpt function of WordPress to get the description for the post in Facebook.
The Implementation
Just Add the following code to your custom_functions.php file in your Thesis Custom folder.
add_action('wp_head', 'add_fb_og_tags');
function add_fb_og_tags()
{
if (is_single() && !is_admin())
{
global $post;
if(get_the_post_thumbnail($post->ID, 'thumbnail')) {
$thumbnail_id = get_post_thumbnail_id($post->ID);
$thumbnail_object = get_post($thumbnail_id);
$image = $thumbnail_object->guid;
} else {
$image = get_post_meta($post->ID, 'thesis_thumb', $single = true);
}
$description = get_the_excerpt($post->ID);
?>
<meta property="og:title" content="<?php the_title(); ?>" />
<meta property="og:type" content="article" />
<meta property="og:image" content="<?php echo $image; ?>" />
<meta property="og:url" content="<?php the_permalink(); ?>" />
<meta property="og:description" content="<?php echo $description ?>" />
<meta property="og:site_name" content="<?php echo get_bloginfo('name'); ?>" />
<?php
}
}
Enjoy Thesis Theme for your WordPress Blog.
But if you are not planning to subscribe through Email. Try subscribing to RSS.
{ 6 comments… read them below or add one }
In thesis when creating a post – you have a spot for the image url for the post image and then you have below that the thumbnail image – but I just place a post image and don’t bother with the thumbnail image because thesis automatically resizes it for you – so can you pull or use the post image so that it is the image that is posted when sharing on Facebook – because as of right now – Facebook tries to pull several images to choose from – but I just want it to pull my post image.
You have to change the following line in the above code
$image = get_post_meta($post->ID, 'thesis_thumb', $single = true);to
$image = get_post_meta($post->ID, 'thesis_post_image', $single = true);The only thing could be that it may return you very large dimension image which Facebook may resize it.
Thanks
The pleasure is all mine.
What if you just want it to use the post image since I’m not setting a thumbnail?
What do you mean by post image? Do you mean an image inside a post or the featured image?