1

I have a problem with how Facebook plugin shows my WordPress-based posts on my timeline. What basically happens is that the post image isn't shown.

Now, the post image I want to show is a custom field of a custom post type, and this is probably what's causing the problem to the Facebook plugin.

On the single-post page I added manually the og: tags, and they're working properly (I see the image if I share the link on Facebook, and the Facebook object debugger shows it too, saying there are no problems).

Do have I to do something to add manually the requested og: tags in post_publish hook?

A sample page is this: http://www.zannoni-store.it/prodotti/canestro-sonoro

And what I added in order to let the image be shown on share is this:

..
$img = get_post(get_post_meta($post->ID, 'immagine', true)); 
echo '<meta property="og:image" content="'.$img->guid.'" />';
..

closed as off-topic by Pieter Goosen, Nicolai, birgire, fuxia Jul 4 '14 at 18:13

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

0

reading the code of the Facebook Official Plugin I've seen that in

open-graph-protocol.php

It's being applied the custom filter 'fb_meta_tags':

..
$meta_tags = apply_filters( 'fb_meta_tags', $meta_tags, $post );
..

So in my plugin I've added a filter for 'fb_meta_tags' that adds/replace the image set from the Facebook plugin in this way:

function clancat_product_fbmeta($meta_tags, $post){
    ..
    $img = get_post(get_post_meta($post->ID, 'immagine', true)); 
    $meta_tags['http://ogp.me/ns#image'] = $img->guid;
    ..
    return $meta_tags;
}

..

add_filter( 'fb_meta_tags', 'clancat_product_fbmeta',10,2);

Please note that the "2" (4th param passed to add_filter) is mandatory, because the Facebook filter it's providing the $meta_tags array and the $post object.

I think this solution ca be easily extended to any post-type / custom-field etc. situation; and that's the correct way to achieve this goal.

Unfortunately this not solve the publish problem.

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