1

We're implementing the Open Graph metatags so that social media shares can know which image to use as the "share" image on our pages. I'm having a problem figuring out the token for a image field URL in a paragraph field.

We have content types with a media field. The node listed under metatags "available tokens" [node:field_media_card:entity:field_media_image]. That by itself didn't work, but I was able to figure out (I don't quite remember how) that the [node:field_media_card:entity:field_media_image:entity:url] token gave the actual URL for the media image. From that point, I was able able to get [node:field_media_card:entity:field_media_image:width] and [node:field_media_card:entity:field_media_image:height], which facebook also wants.

So that works for those content types with media fields.

However, for other content types, we have a paragraphs field with an image field in it. It's a custom paragraph with a custom field in it. Our paragraph is called "Jumbotron Hero" and the field in question is called "Background Image". I am having trouble creating a token to get the URL of its image.

The Available Token lists [node:field_jumbotron_hero:entity:field_background_image]. However I tried both [node:field_jumbotron_hero:entity:field_background_image:url] and [node:field_jumbotron_hero:entity:field_background_image:entity:url], but neither set the og:image value. Along with the URL, I also want the height and width.

How can I figure out the token to get the url, height, and width of this field?

  • If the node image field is a media field then the one in the paragraph probably as well? Then you need a third :entity and the field name of the image file in front of :url. – 4k4 Sep 14 '18 at 20:32
  • @4k4 sorry I'm having a little trouble following you-- can you spell out exactly what you think the proper token might be, using placeholders (i.e. yourfilefieldnamehere) where necessary? – user1359 Sep 14 '18 at 20:41
  • 2
    You didn't answer my question, but if the field field_background_image is a media field, then you need to append :entity:field_media_image:entity:url. – 4k4 Sep 14 '18 at 21:19
  • @4k4 Sorry I misunderstood. The field field_background_image is actually an image field. – user1359 Sep 16 '18 at 3:12
  • this is very similar to drupal.stackexchange.com/a/271750/25141 you probably need the field_paragraph_name:entity added into one of these tokens before the media-reference field – bdanin Oct 30 '18 at 1:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.