Leave a Reply

1 comment

  1. 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.