WordPress.org

Ready to get started?Download WordPress

Forums

Facebook
Customize Open Graph protocol for your site or network (19 posts)

  1. Facebook
    Member
    Plugin Author

    Posted 1 year ago #

    WordPress filters allow themes or plugins to customize the functionality of WordPress software including activated themes or plugins. The Facebook plugin for WordPress exposes filter interfaces throughout its code for customization by other plugins including plugins specific to your site.

    Customizing Open Graph protocol output is a common request from site owners. The Facebook plugin for WordPress builds Open Graph protocol outputs targeting the configuration of most sites. It is possible to customize Open Graph protocol properties before output to the page through the fb_meta_tags filter.

    Example: add a fallback image for all pages on your site or network.

    /**
     * Add site-specific Open Graph protocol customizations to the Facebook plugin
     *
     * @param array $meta_tags an associative array of Open Graph protocol properties with keys expressed as full IRIs
     * @return array plugin default values with site-specific customizations
     */
    function my_ogp_filter( $meta_tags ) {
    	$meta_tags['http://ogp.me/ns#image'][] = array(
    		'url' => 'http://s.wordpress.org/about/images/logos/wordpress-logo-notext-rgb.png',
    		'type' => 'image/png',
    		'width' => 500,
    		'height' => 500
    	);
    	return $meta_tags;
    }
    add_filter( 'fb_meta_tags', 'my_ogp_filter' );

    The above example asks WordPress to pass requests for modifications to the Open Graph properties (identified by the fb_meta_tags filter) through the my_ogp_filter function. Your function modifies the passed-in variable and returns the modification. The example function above adds the WordPress logo as a featured image on every page. If a post does not have its own featured image the WordPress logo would appear in a shared story summary on Facebook.com. Posts with a featured image would offer the WordPress logo as an alternate choice inside a story preview.

    You might place this custom function inside your theme's functions.php file or as a separate PHP file in your site's must use plugins directory (e.g. /wp-content/mu-plugins/facebook-custom.php).

  2. Graham Stoney
    Member
    Posted 1 year ago #

    Thanks for your plugin. I think the ability to specify a fallback image really ought to be built into the plugin; lots of other OpenGraph generating plugins have this feature.

    Cheers,
    Graham

  3. v.dupont
    Member
    Posted 1 year ago #

    Hello,

    I have featured images on all of my posts.
    However, when I publish a post to facebook, the featured image is never used. Facebook always takes one picture from the page, randomly.

    When I check my source code, there are various OG meta tags, but none relating to a image.
    Is this normal?

    thanks
    vincent

  4. v.dupont
    Member
    Posted 1 year ago #

    Hello,

    (wordpress 3.5.1, plugin Facebook 1.2.2)

    when the featured image is a picture from one NextGen Gallery,the plugin does not mention any image meta tag (Og tag)

    Inside the file open-graph-protocol.php,line 294, the call to get_post_thumbnail_id( $post->ID ) does return a thumbnail ID like "ngg-789".
    As a consequence, the function call "wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full' );" cannot find any information about the URL, width and heigh of this thumbnail (these variables are empty strings)...

    Could you please try to provide a support for nextGen Gallery thumbnails ?
    Or do you know what could I use instead of "wp_get_attachment_image_src" to stay compatible with NextGen Gallery?

    thank you for this very nice plugin!
    vincent

  5. cybecom
    Member
    Posted 1 year ago #

    This was absolutely working with the featured image pulled from the normal media image gallery recently. Now it is not. I could set a featured image and know with 100% certainty that it would appear as the image for the Facebook post. Now I can't. The only thing I believe has changed since it was last working are two or three point releases of the plugin. In my case, there is no randomness about what image it pulls. It pulls the first image it sees on the page post which happens to be in my sidebar and not what I want to use. I've tried other plugins that set the og:image but they are ignored and the debugger picks up duplicate errors. For a whole lot of obvious reasons, I am reluctant to use my own code to solve this issue.

  6. cjeyes
    Member
    Posted 1 year ago #

    I have to say that it is surprising that for something which would be as popular as Facebook, with a function as basic and obvious as choosing what image you want displayed for your site's likes, we seem to be expected to be dabbling in changing code and php files.
    This is seriously annoying - I spend time designing a logo for my firm's [link moderated] online conveyancing site, expecting it to be used in any likes the site attracts, and yet what I get is the Lexcel logo and not the one I spent time on.
    I would strongly suggest that a basic and obvious function for the plugin is to specify a default image as part of the settings.
    Thanks,
    Chris

  7. siddhu
    Member
    Posted 1 year ago #

    Failed posting to your Facebook Timeline. Error: {"message":"(#100) You haven't enabled Explicitly Shared for this action type (331247406956072) yet. Please update your Open Graph settings in the App Dashboard","type":"OAuthException"}

    Whats This Error ?

  8. pnaw10
    Member
    Posted 1 year ago #

    @ v.dupont: You said that Facebook will randomly show an image OTHER than the one you specified as the post's featured image.

    Just something I discovered myself recently: Facebook prefers images that are at least 200x200 pixels. For years, the featured images on my site have been 200x150, which is smaller than what FB wants.

    If I publish a post with no other images, Facebook will honor the featured image since there's no other choice. But if a post includes other images, FB will simply ignore the og:image tag and automatically take the first image in the post which exceeds 200x200 pixels.

    Put any URL into the Facebook Debugger and you'll see exactly which OpenGraph tags are "seen" by Facebook, and whether any of these tags are generating problems or error messages. That's how I realized FB was ignoring my featured images (if a bigger image is available).

    https://developers.facebook.com/tools/debug

    When it comes to using other plugins to manage your images, I can't help you there. And I agree with cjeyes' comment about how we shouldn't have to involve ourselves into tinkering with code just to make such a simple thing happen.

    With the new FB news feed being announced yesterday, I'm now trying to find a way to bring my sites into compliance with Facebook's "demand" that featured images be at least 200x200 pixels, but "preferably" as large as 1500x1500 pixels. I'm trying to figure out how to make new posts display "normal" images on my site, while feeding the gigantic 1500px images to Facebook.

  9. v.dupont
    Member
    Posted 1 year ago #

    hello pnaw10
    thank you for your reply.

    I've added a meta with my logo as default image. this is 200x200.
    If the plugin does not add a meta og image in the head, facebook takes the default one.

    I had just to care that the post image is listed first and the default logo next.
    So it works.
    I hope to have no problem with the new request for larger images (1500x1500)....

    Vincent

  10. paulmack
    Member
    Posted 1 year ago #

    well that worked great, I changed the other images on the page to 190px x 190px and it still took the wrong image even though the post image was 400 x 400 DOH!

  11. Niall Kennedy
    Member
    Plugin Author

    Posted 1 year ago #

    You should test the results of your changes in the Facebook URL debugger to view any current issues with your webpage.

  12. ekowp
    Member
    Posted 1 year ago #

    It would be easier if someone on Facebook make a step by step tutorial how to setup Social Publisher. Screenshot would really helpful, but please don't throw much technical jargon, just show us steps how to make it works.

    I'm stuck at:

    2. Associate an Open Graph action-object pair for your application: people can publish an article.

    When I click create a new story button on facebook there's a new window with empty action type list. Then I type "Publish" and select an object type "Article". After clicking create button, it show this error:

    A custom Publish action is restricted. Please use the common Publish action instead.

    Ya sure, there's a documentation and video tutorial, but man it only helpful if you really knows what they talking about. Full of jargon even in the video, she use a VI text editor. It would alienate most of wordpress user who at first want to use this plugin. The reason WP so popular because it can be setup even by non-technical user. That's different with facebook plugin.

  13. alicea
    Member
    Posted 1 year ago #

    Help! I'm a complete web/Wordpress newbie. I tried to install the code above into the Facebook plugin and my theme's functions.php file. I now can't log onto my website (wp-admin). I get the following error message:

    add_theme_support( 'post-thumbnails' );
    Warning: Cannot modify header information - headers already sent by (output started at /home/wrwr2059/public_html/wp-content/themes/Exhibit/functions.php:215) in /home/wrwr2059/public_html/wp-includes/pluggable.php on line 876

    Arrrgggh! Can anyone tell me how to reverse this.

  14. Give this a read and see if you can restore an unedited copy of that file wp-content/themes/Exhibit/functions.php

    Looks like you left a blank space/line somewhere when you modified that file.

    That's a commercial theme so you should be able to get a fresh copy from ThemeForest using your account.

    http://themeforest.net/item/exhibit-retina-responsive-wordpress-theme/3958416

  15. alicea
    Member
    Posted 1 year ago #

    Thank you so much Jan - really appreciate your speedy response.

  16. CarolWP
    Member
    Posted 1 year ago #

    Is there a way to do this for the title? For the title that shows on the page, the title in the <title> function, and the title in the RSS feed, I've modified the title to include the custom post type before the title. For example, the "Accounting" page in the Employee Benefits Library has the title "Employee Benefits Library: Accounting". However, I cannot figure out what the code would be to make the og:title attribute also be "Employee Benefits Library: Accounting" instead of just "Accounting".

  17. CarolWP
    Member
    Posted 1 year ago #

    Okay, I answered my own question. Here's the code:

    function change_fb_meta_type($metatags) {
    if (get_post_type($post) == 'clg_library') {
    $metatags['http://ogp.me/ns#title'] = 'Employee Benefits Library: '. get_the_title();
    }
    return $metatags;
    }
    add_filter('fb_meta_tags', 'change_fb_meta_type');
  18. filimm
    Member
    Posted 1 year ago #

    Hi, is it possible to

    'url' => 'http://s.wordpress.org/about/images/logos/wordpress-logo-notext-rgb.png',

    this content instead be a fixed url be a php variable like:

    'url' => '$url',

    ?

  19. Niall Kennedy
    Member
    Plugin Author

    Posted 1 year ago #

    filimm: in PHP you should pass the $url variable as the value of the associative array. The Facebook plugin for WordPress will output the string as your page is generated.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic