I have a content type called "article" that I've given a "featured image" field, which I'm using for the og:image metatag by using the [node:field_featuredimage] token. However, not all of my nodes of my "article" content type have a featured image.

For articles that have a featured image, the og:image metatag is printed correctly.

For articles that have an empty field_featuredimage, no og:image metatag is printed at all, presumably because getValue returns nothing when expanding the token.

I have a default og:image set for all content types, and I'd like articles with an empty field_featuredimage to display the default image I've set instead of displaying no tag at all.

Is this behaving as designed or is it a bug? Or should this be a feature request?

Comments

Nightwalker3000’s picture

Same issue here. Did you find a solution?

hawkeye217’s picture

My solution is kind of a hack, but it works. I added this in my mytheme_preprocess_html() in template.php:

  $element = array(
    '#tag' => 'meta', 
    '#attributes' => array(
      'property' => 'og:image',
      'content' => "http://path-to-my-default-image.jpg",
    ),
  );
  drupal_add_html_head($element, 'og_image_default');

I also added this function to template.php, which as an alter function runs after the metatags module inserts its code - it just checks to see if metatag has added an og_image, and if it has, it removes my default that my preprocess function added:

function mytheme_html_head_alter(&$vars) {
	if (isset($vars['metatag_og:image']) ) { 
		unset($vars['og_image_default']); 
	}
}

Hope that helps!

damienmckenna’s picture

Status: Active » Fixed

This should work with the latest codebase, please let me know if you're experiencing problems with it.

damienmckenna’s picture

Status: Fixed » Closed (fixed)
ibedoya’s picture

Status: Closed (fixed) » Active

I still have this problem. Also with an image and og:image.

I have the default 'field_image' for 'Article' content type.

I put a defaut image for 'Global'. Also I've tried to set a default image for 'Content'(node).
In both cases when I don't put the image, the default image isn't used.

In wich commit was fixed?

damienmckenna’s picture

Status: Active » Closed (fixed)

For any issues with beta4 please focus on #1845326: Metatags not loading correctly with beta4. Thank you.