I used this code before the in my wp theme
this before the <head>:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:og="http://ogp.me/ns#"
xmlns:fb="http://www.facebook.com/2008/fbml">
after <head> this:
<meta property="og:title" content="<?php the_title() ?>"/>
<meta property="og:fb:app_id" content="1111111111"/>
<meta property="og:type" content="article"/>
<meta property="og:url" content="<?php the_permalink() ?>"/>
<meta property="og:image" content="<?php echo catch_that_image() ?>"/>
<meta property="og:site_name" content="<?php bloginfo('name') ?>"/>
<meta property="fb:admins" content="USER_ID"/>
<meta property="og:description" content="<?php echo strip_tags(get_the_excerpt($post->ID)); ?>"
<?php function og_meta_desc() {
global $post;
$meta = strip_tags($post->post_content);
$meta = str_replace(array("\n", "\r", "\t"), ' ', $meta);
$meta = substr($meta, 0, 200);
echo "<meta property=\"og:description\" content=\"$meta\"/>";
}
og_meta_desc();
?>
and in function.php this:
function catch_that_image() {
global $post, $posts;
$first_img = '';
ob_start();
ob_end_clean();
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
$first_img = $matches [1] [0];
if(empty($first_img)){ //Defines a default image
$first_img = "/images/default.jpg";
}
return $first_img;
}
but get the first image, how i get the "featured image" of each of post?
And in developers.facebook.com/tools/debug/ it gives me these messages:
Scrape Information
Response Code: 502
Fetched URL: www.mysite.com/post-1
Canonical URL: www.mysite.com/post-1
Critical Errors That Must Be Fixed
Error Scraping Page: Bad Response Code
Open Graph Warnings That Should Be Fixed
Inferred Property: The og:url property should be explicitly provided, even if a value can be inferred from other tags.
Inferred Property: The og:title property should be explicitly provided, even if a value can be inferred from other tags.
Have I done something wrong, is there another "correct" way for wordpress site? If I did how can I fix it?