What's the simplest way to add an OpenGraph image tag to your posts for Facebook?
-
I don't need a full Like button implementation, or really any OpenGraph tag other than the image. (I've got ShareThis handling the "Like" button, and the title and meta description are sufficient for now). What I'm looking for is a plugin that will automatically choose the first image from the content (if present), and maybe have a fallback image if the individual post or page doesn't have one. Being able to choose a specific image would be nice as well, but I've got two blogs with a combined backlog of over 4,000 posts, and I don't want to use a plugin that requires me to set the image manually on every single post. I can write one if I have to, but I don't want to reinvent the wheel if it's already out there, and besides, it's a matter of finding the time. Thanks!
-
Answer:
From where I stand on this topic you have two choice: 1) Implement what mentioned at:Optimising the Facebook Open Graph Protocol http://yoast.com/facebook-open-graph-protocol/ Adding some Necessary Facebook Open Graph Tags: <meta property="og:title" content="<?php the_title(); ?>"/> <meta property="og:description" content="<?php if ( function_exists('wpseo_get_value') ) { echo wpseo_get_value('metadesc'); } else { echo $post->post_excerpt; } ?>"/> <meta property="og:url" content="<?php the_permalink(); ?>"/> <meta property="og:image" content="<?php echo get_fbimage(); ?>"/> <meta property="og:type" content="<?php if (is_single() || is_page()) { echo "article"; } else { echo "website";} ?>"/> <meta property="og:site_name" content="<?php bloginfo('name'); ?>"/> Put the code above in your theme's header.php Generating the best Image Thumbnail function get_fbimage() { $src = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), '', '' ); if ( has_post_thumbnail($post->ID) ) { $fbimage = $src[0]; } else { global $post, $posts; $fbimage = ''; $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches); $fbimage = $matches [1] [0]; } if(empty($fbimage)) { $fbimage = "http://mydomain.com/default-image.jpg"; } return $fbimage; } put the code above in your theme's function.php make sure you update the default-image.jpg to something relevant for your site. or 2) Wait for WordPress SEO Plugin (http://yoast.com/wordpress/seo/) to be updated.
Azizur Rahman at Quora Visit the source
Other answers
This Article describes clear way of adding Facebook opengraph to your WordPress Themes/Websites http://flowwithtimes.com/integrate-facebook-open-graph-with-wordpress-themes-without-plugin/
Dham Bhattarai
Related Q & A:
- What's the easiest way to scrape residential phone numbers and names into .csv format?Best solution by Quora
- What's the best way to get into the Graphic Design industry?Best solution by Yahoo! Answers
- What's a fast way to lose weight?Best solution by Yahoo! Answers
- What's the quickest way to solve a Rubik's Cube?Best solution by Yahoo! Answers
- What's the new way to delete multiple pages on facebook?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.