og:image is not set if we use Media Field instead of File Field. Accordding to devel token tab, the token is correctly filled but not metatags.

I'm using Media-7.x-1.x branch


emosbaugh’s picture

Version: » 7.x-1.x-dev

Same issue here

emosbaugh’s picture

I 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.

emosbaugh’s picture

Ok, 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.

emosbaugh’s picture

Status: Active » Closed (works as designed)
AdamGerthel’s picture

Did you manage to find a solution?

mrfelton’s picture

I got this working with a token like [node:field-ss-portfolio-teaser-image:file:url]

marcvangend’s picture

Issue summary: View changes

In 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).

markconroy’s picture

I had this issue with Drupal 8 using the media entity module this morning. Here's how I solved it:


Here's a short blog post I wrote up about it with more details:


DamienMcKenna’s picture

Thanks Mark, I've added a link to it from the module's project page.