Closed (works as designed)
Project:
Metatag
Version:
7.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
7 Nov 2011 at 14:33 UTC
Updated:
1 May 2020 at 00:55 UTC
Jump to comment: Most recent
Comments
Comment #1
emosbaugh commentedSame issue here
Comment #2
emosbaugh commentedI spent a long time on this and I have figured out how to get it to work without need for a patch. What is happening is the token is getting replaced with whatever file view mode is set in your default content type display {admin/structure/types/manage/{content-type}/display/default}. This is most likely the file display, and when the tag is inserted into the head of the HTML document, the HTML tags are stripped out (<img>).
The solution is to enable the custom display for view mode "Tokens." After that you can create a file view mode for the url or link to the media image and set that as the file view mode in the display view mode format settings.
I'm not sure if the default behavior before all this set up is not a bug as it seems that image field works out of the box with this. I will try to look into this next.
Comment #3
emosbaugh commentedOk, it looks to me like the is a media module issue. Not so much an issue, but a feature request for default token support. The token module provides a default_token_formatter for core fields, which is necessary for token support. As the media field is deprecated I doubt there will be support for this in the future.
Although it looks like this issue may be dead in the water, this was a great opportunity for me to dive deep into the field and token apis.
Comment #4
emosbaugh commentedComment #5
adamgerthel commentedDid you manage to find a solution?
Comment #6
mrfelton commentedI got this working with a token like [node:field-ss-portfolio-teaser-image:file:url]
Comment #7
marcvangendIn my case (and 2 years later :-)) I got it working with this token:
[node:field-media:0:file:url](where "field-media" is the field name, with underscores replaced with dashes).Comment #8
markconroy commentedI had this issue with Drupal 8 using the media entity module this morning. Here's how I solved it:
[node:field_main_image:entity:field_m_image_image]
Here's a short blog post I wrote up about it with more details:
https://mark.ie/blog/web-development/adding-tokens-metatag-image-fields-...
Comment #9
damienmckennaThanks Mark, I've added a link to it from the module's project page.
Comment #10
rajveergangwarThanks mark,
Its working for me but adding entity:url in token
https://www.drupal.org/project/metatag/issues/1334256#comment-12299624
Comment #11
parthabapari commentedAfter struggling two day's and applying all the possible tokens suggested in this discussion finally this post
https://mark.ie/blog/web-development/adding-tokens-metatag-image-fields-... suggested by @markconroy
worked for me. After reading this article I got to understand clearly the issue was with my token format. In my case both image field on my content type and the name of the image field on my image media bundle were the same.
Hence my token is [node:field_media_image:entity:field_media_image:full_content_hero_image:url]
field_media_image => Image field on my content type
field_media_image => Image field on image media bundle.
full_content_hero_image => Image style
Hope helps someone in same situation as me.