I have installed the Metatags module along with the Open Graph and Twitter Card extension modules. In my default content type, I have added an Image field that allows an image to be uploaded for use on Facebook and Twitter.

Now I cannot get the Metatags module to accept this image custom field as the entry for the og:image and Twitter Card Image fields. I've tried entering [node:field_image] but the meta tags do not get added to the source code. If I enter a URL the tags appear.

How do I get Metatags to dynamically include a corresponding image for each page in the Open Graph and Twitter Cards metadata?

2 Answers 2


I used drupal_add_html_head in my case. In my theme template.php.

$og_image = image_style_url('200x200', $node->field_gallery_preview_image[LANGUAGE_NONE][0]['uri']);
// OG image meta property.
  '#tag' => 'meta',
  '#attributes' => array(
    'property' => 'og:image',
    'content' => $og_image,
), 'node_' . $node->nid . '_og_image');
  • How to add og image for users??? replace node with users?
    – jack
    Oct 6, 2014 at 23:58

I fixed editing my template.php > MYTHEME_html_head_alter.


function YOURTHEME_html_head_alter(&$head_elements) {
  // Overwrite og:image file
  $head_elements['opengraph_meta_og:image']['#attributes']['content'] = "path/to/your/image.jpg" ;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.