2

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?

3

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.
drupal_add_html_head(array(
  '#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 '14 at 23:58
0

I fixed editing my template.php > MYTHEME_html_head_alter.

Code:

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, privacy policy and cookie policy

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