简体   繁体   中英

Wrong og:image in the Facebook Open Graph

I did the Open Graph on my website and everything is perfect.

But, for the homepage (front_page), facebook takes an image of FOOTER (?!)

In the debug is alright. How to force facebook to make the OG: IMAGE as first image?

The code:

<?php if (have_posts()):while(have_posts()):the_post(); endwhile; endif;?>
<!-- the default values -->
<meta property="fb:app_id" content="MY ID" />

<!-- if page is home -->
<?php if (is_front_page()) { ?>
<meta property="og:title" content="name" />
<meta property="og:type" content="article" />
<meta property="og:url" content="http://www.com/"/>
<meta property="og:image" content="http://www.com/wp-content/uploads/2013/02/thumbface.jpg" /> <?php } ?>

<!-- if page is content page -->
<?php if (is_single()) { ?>
<meta property="og:title" content="<?php single_post_title(''); ?>" />
<meta property="og:type" content="article" />
<meta property="og:url" content="<?php the_permalink() ?>"/>
<meta property="og:description" content="<?php echo strip_tags(get_the_content($post->ID)); ?>" />
<meta property="og:image" content="<?php $fbthumb = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'facebook-thumb' ); echo $fbthumb[0]; ?>" />

<!-- if page is others -->
<?php } else { ?>
<meta property="og:site_name" content="<?php bloginfo('name'); ?>" />
<meta property="og:description" content="<?php bloginfo('description'); ?>" />
<meta property="og:image" content="http://www.com/wp-content/uploads/2013/02/thumbface.jpg" /> <?php } ?>

and sorry for my bad english

Debug the URL on Facebook's Debug Tool . There's a possibility that your URL has been cached by Facebook even though the image would be the correct one. Using the Linter will delete the cache, and use the presently available tags on the page.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM