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?

link|improve this question

20% accept rate
Your post title doesn't really correspond to the only real question I can find in your question, that is: "how i get the "featured image" of each of post?". – Chip Bennett Jan 27 at 20:06
feedback

1 Answer

but get the first image, how i get the "featured image" of each of post?

Use get_the_post_thumbnail(). You simply need to pass it the ID of the post; e.g.:

<?php
global $post;
$post_thumbnail = get_the_post_thumbnail( $post->ID );
?>
link|improve this answer
i replace everywhere in code of function.php the word first_img with post_thumbnail but still get the first image or nothing, have I done something wrong? – Alex Jan 28 at 14:36
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.