5

On a Drupal 8 content type, I have a field with an entity reference field to a Media Entity field. I would like to use the Metatag module to set the image that is on this Media entity in the og:image meta tag.

  • Featured Image - [node:field_im] - Returns the entity name
  • Featured Image type with delta 0 - [node:field_im:0] - Returns the entity name
  • Media - [node:field_im:0:entity] - Returns the entity name
  • Media ID - [node:field_im:0:target_id] - Returns the entity ID

In Drupal 7, the following token was available:

[node:field-fimg:0:file:url]

But I don't see anything like it in D8. Could someone point me in the right direction?

7

If I understand your question correctly you'll need to do the following:

  • Check on your modules page that the "Metatag: Open Graph" submodule is enabled.
  • Go to metatag config page (Configuration > Search and metadata > Metatag).
  • Add a new "default metatag" and select your content type in the "Type" selectbox.
  • Fill in the rest of the fields similar like following picture (just don't forget to use your own field names:

enter image description here

Here are some things you need to know about my tokens:

  • field_teaser_img: is the fieldname of my media entityreference on my content type.
  • field_me_img: is the fieldname of my image field on my media entity type.
  • facebook: is the imagestyle name I created for these metatags
  • height, mimetype & width: are property fields of the media entity type yet I didn't create those fields but it does seem to work.

I hope this helps.

  • Thanks Hatznie, while those options weren't in the Token browser, they do work. My solution for the Media Entity Image bundle is as follows: [node:field_im:entity:image] – thejimbirch Dec 1 '16 at 15:27
  • 2
    I found that this solution pointed me in the right direction, but gave me a relative URL. This instead printed an absolute URL: [node:field_teaser_img:entity:field_me_img:entity:url] (using your field name examples) – John Mar 23 '18 at 19:01
1

From http://drupalsun.com/glassdimly/2017/08/23/drupal-8-how-get-image-style-tokens-metatags

[node:field_my_image_field:entity:field_image:my_image_style:url]
[node:field_my_image_field:entity:field_image:my_image_style:width]
[node:field_my_image_field:entity:field_image:my_image_style:height]

This worked very well for me, where field_my_image_field is my media-reference-field name

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.