Hey all,

How hard would it be to include a custom definition for og:image per node-type in a similar way to how the og:description is allowed to be set per node-type for the module currently?

This would be a wonderful feature - right now for some reason I'm finding that my default image is loading for all posts on my site when I haven't specifically selected an image to use per node.

I'd love to simply select a cck imagefield per node-type to be the de facto og:image.

Any ideas/suggestions/help would really be welcome...

Qasim

Comments

designguru’s picture

Incase anyone is looking for the same functionality, I hacked up some php in my page.tpl.php file's header section - just below the page title so that this code gets loaded before the module-powered og tags.

<?php if ($node->type == 'blog'): ?>
<meta property="og:image" content="http://www.website.com/<?php print ($node->field_logo[0]['filepath']); ?>" />
<?php endif; ?>

The above will print a field called 'logo' in the 'blog' type's og:image header declaration and still let the module do its thing - which means that Facebook will offer you two options for a thumbnail image - the imagefield powered one from the solution above, and the de facto image for your site as set in the module settings.

:)

Cheers,

Qasim

venusrising’s picture

You are a genius. Been killing myself over this. BTW to tell Facebook a default image without a module we did

in template.php
function ourtheme_preprocess_node(&$vars, $hook) {
global $user;
if(arg(0) == 'node') {
if(!empty($node->field_ourimage[0]['view'])) {
drupal_set_html_head('
href="'.check_url($node->field_ourimage[0]['view']).'" />');
} else {
drupal_set_html_head('
href="http://www.xxx.com/files/xxx_logo.png" />');
}
}

So, with your hack we get the node image first and our logo if empty OR someone wants to choose it.
We also added meta property="og:type" content="article"/ (had to remove arrows in this ost as it would not print but you need the <> also) so we had one more graph tag of type

THANKS!

k3vin_nl’s picture

I agree, it would be great to select a default way to select the image per node type. For example a choose a cck image field per node-type.
For now we solved it like this in preprocess_page().
If we have a node with cck field-image the default open graph image tag is removed and a new one added. Would be great if this could be done via a configurable setting!

<?php
 // if we have an image attached to the node use that instead of the default image...
  if (module_exists('fb_social_like') || module_exists('fb_social_comments')) {
    if ($node->field_image){
      // we have an image build the new facebook metatag..
      $filepath = url($node->field_image[0]['filepath'], array('absolute' => TRUE, 'alias' => $aliased ));
      $data = '<meta property="og:image" content="' .  $filepath . '"/>' . "\n";
      $head = drupal_get_html_head();
      // remove defautl facebook image from head
      $head = preg_replace('/<meta property="og:image"[^>]+\>/i','',$head);
      // build new head:      
      $variables['head'] = $head . $data;
    }
  }
?>
venusrising’s picture

Now the question would be how to get this to work for a frontpage view. We have a custom tpl but it does not respect the image.

hiddentao’s picture

I think what's needed is a hook which allows you to modify the value of the og:image tag for each node just before it gets output.

hiddentao’s picture

Added a new hook in latest dev release: og_tag_render_alter

Documentation in opengraph_meta_test_module.module

/**
   * Implements hook_og_tag_render_alter().
   *
   * @param $node the node whose tag is being rendered.
   * @param $name the name of the OG tag being rendered, e.g. title, image.
   * @param $value the value of the OG tag being rendered.
   *
   * @return the altered value to render for the given tag.
   */
windm’s picture

Hi there!

Is it really required to put things in the page.tpl or to rewrite things as a preprocess?

I have the same requirement (to have the #1 image of a node as the default thumbnail for fb sharing) and the same situation/experience:
- OG Meta tags takes always(!) the "fallback image" that is defined at admin/content/opengraph_meta/settings if I don´t edit the node manually
- in the node/*/edit form I find the "Open Graph meta tags" settings where all existing CCK-imagefields are offered as the thumbnail... so I simply need to check the radio-button and everything is fine (means the right image is posted to fb!)
- for this reason, users without permissions to edit the OG meta tags, can´t change the thumbnail...

So all I would ask for, is that the first available radio button should be checked by default...

shaneonabike’s picture

+1 this would be super useful to be honest since the scraping off my site is producing lots of useless images :( Also weirdly enough I couldn't get your hook to invoke after many flushes and different attempts... strange.

  • hiddentao committed 511990b on 7.x-2.x
    Issue #1283234 by hiddentao: Added "og_tag_render_alter hook" for...
torotil’s picture

Version: 6.x-1.x-dev » 7.x-2.x-dev
Issue summary: View changes
Status: Active » Fixed

Version 7.x-2.x now builds on metatag. So it now is possible to set a default image per bundle/content-type and still use the image-select from opengraph_meta.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.