• Resolved It’s Thomas!

    (@itsthomas)


    Hello!

    my problem: I would like to have one certain image to be shown when a post is shared via facebook / google+, even on the posts which contain an image themselves.
    The problem is that even though I have selected a featured image for these posts other than the one they contain, when sharing via facebook / google+, the wrong image (the one which is contained in the post) is used.

    Looking at the code which is inserted by your plugin, I can see that there are meta property="og:image" as well as <!-- Scope BEGIN: ImageObject --> meta itemprop="url" meta itemprop="thumbnailUrl" meta itemprop="contentUrl" <!-- Scope END: ImageObject --> values inserted for the image in the post which I don’t want to be displayed. These values are also inserted for the featured image I have selected but still, the image used on facebook / google+ shares is the wrong one.

    Can you offer advice?

    Thanks

    Thomas

    https://wordpress.org/plugins/add-meta-tags/

Viewing 15 replies - 1 through 15 (of 24 total)
  • Plugin Author George Notaras

    (@gnotaras)

    Hi Thomas,

    The plugin by default generates meta tags for all attached and embedded (only Flickr is currently supported) images. There are no plans to change this behavior. Perhaps an option will be added in the future to generate meta tags only for the featured image, but this is not a guarantee that the aforementioned services will use that one.

    At the time of writing the plugin, it was unclear which image would be used as the default by FB/G+. Some people claimed the first or last one of the list was preferred, while others claimed that the services used the image with the most suitable size. It is actually really difficult to say which image is the right one and which is the wrong one.

    So, unless there is some solid information about this issue, I think it is pointless to make any changes to the order the plugin generates image meta tags, which is:

    1) The featured image
    2) Other attached images (locally hosted)
    3) Embedded images (currently supports only Flickr)

    This order was the one that made sense, so I decided to go ahead with that.

    You can always experiment by filtering the generated opengraph meta tags programmatically (1st one is always the featured image) and see what happens. Please, see example 1 in the description page.

    George

    Plugin Author George Notaras

    (@gnotaras)

    Thread Starter It’s Thomas!

    (@itsthomas)

    Hi George,

    thanks for your fast and informative reply (as usual)!

    I thought about it: Is it possible to exclude single posts / pages from the automatic generation of meta data? (I know this possible for specific post types, as described in example 2.)
    If I could do this, then I would just put my individually changed meta tags in the meta tags box on the edit screen and try out a few things…

    Thanks a lot

    Thomas

    Plugin Author George Notaras

    (@gnotaras)

    Hello Thomas,

    I thought about it: Is it possible to exclude single posts / pages from the automatic generation of meta data? (I know this possible for specific post types, as described in example 2.)

    It can be done as shown in example 2, in which an empty array should be returned:

    function limit_metadata_to_post_types( $post_types ) {
        return array();
    }
    add_filter( 'amt_supported_post_types', 'limit_metadata_to_post_types', 10, 1 );

    If I could do this, then I would just put my individually changed meta tags in the meta tags box on the edit screen and try out a few things…

    Also, if you just want to remove the ‘og:image’ metatags from the Opengraph metadata and experiment by adding your own ‘og:image’ meta tags in the ‘Full Meta Tags’ box in the post editing screen (need to be enabled in plugin settings under ‘Metabox Features’), this code could help:

    function amt_opengraph_no_images( $metatags ) {
        $og_final = array();
        foreach ( $metatags as $metatag ) {
            if ( strpos($metatag, 'og:image') === false ) {
                $og_final[] = $metatag;
            }
        }
        return $og_final;
    }
    
    // Suppress width/height/type meta tags for images for easier exclusion
    add_filter( 'amt_extended_image_tags', 'amt_return_false', 10, 1 );
    // Exclude 'og:image' meta tags from OpenGraph metadata
    add_filter( 'amt_opengraph_metadata_head', 'amt_opengraph_no_images', 10, 1 );

    George

    Plugin Author George Notaras

    (@gnotaras)

    Hi Thomas,

    If you don’t get expected results by using the code above, please let me know.

    George

    Thread Starter It’s Thomas!

    (@itsthomas)

    Hi George,

    I just put the following code into the functions.php of my (child) theme:

    function limit_metadata_to_post_types( $post_types ) {
    return array();
    }
    add_filter( ‘amt_supported_post_types’, ‘limit_metadata_to_post_types’, 10, 1 );

    Result: While the plugin itself is still activated (I can get into the options page), the meta data seems to be removed from all posts & pages and there are no fields from your plugin in the edit screens visible.

    So something obviously went “wrong” – should I have modified the code?

    Thanks

    Thomas

    Plugin Author George Notaras

    (@gnotaras)

    No worries, metadata is fine, it’s just not displayed. Using this method apparently does not give the expected result.

    You will have to use the second method to stop generating the og:image meta tags.

    Or to completely stop the generation of Opengraph meta tags, add the following:

    function amt_no_opengraph( $metatags ) {
        return array();
    }
    add_filter( 'amt_opengraph_metadata_head', 'amt_no_opengraph', 10, 1 );

    Hope this helps.

    George

    PS: The provided sample code does not affect the stored data in any way.

    Plugin Author George Notaras

    (@gnotaras)

    … or just disable it in the configuration panel (where is my mind..)

    Plugin Author George Notaras

    (@gnotaras)

    Using this method apparently does not give the expected result.

    I’ll look into this at some later time.

    Thread Starter It’s Thomas!

    (@itsthomas)

    I will try out disabling OpenGraph meta tags and inserting my own tags later and get back with the results.

    If you look at this issue again: Just having the option to disable automatic meta tags generation with single posts / pages via posts / page ID while still having the meta tags box in the edit screen to insert one’s own tags would be most handy, I’d guess IMHO.

    Thanks again!

    Thomas

    Thread Starter It’s Thomas!

    (@itsthomas)

    Just tried it… the only og:image tags in the code of the page were of the image I wanted to be displayed when shared via facebook. It did not work! Facebook still used the image that is inserted in the post…hmpf?!

    Plugin Author George Notaras

    (@gnotaras)

    I’d suggest doing the following to make sure: Add a single og:image meta tag pointing to the image you want to use (make sure the image size follows the specs) and then use facebook’s debug tool to get a new scrape of the page. This will force the service to refresh its cache.

    Hope this helps

    George

    Plugin Author George Notaras

    (@gnotaras)

    Hello Thomas,

    Any new findings about the issue?

    Thread Starter It’s Thomas!

    (@itsthomas)

    Hi George,

    thanks so much for caring! 🙂
    I’m sorry but real life got me on my knees… will post here when I can!

    Thomas

    Plugin Author George Notaras

    (@gnotaras)

    No problem. Please take your time. I’m also posting on these forums whenever I have the time to do so. 🙂

    George

Viewing 15 replies - 1 through 15 (of 24 total)

The topic ‘Wrong image shown on facebook / google share’ is closed to new replies.