Can't find the right token (URL) for og:image in Drupal 10

Created on 11 September 2023, 10 months ago

Problem/Motivation

My setup is: Drupal 10.1.3 and Metatag 2.0.0

In all of my content types, I have the same image field:
Label: Image
Machine name: field_media_image
Field type: Entity reference
Reference type: Media
Media type: Image

I'm trying to add og:image metatag to my pages for all content types.

So I've enabled 'Metatag: Open Graph' submodule and proceeded to:
admin/config/search/metatag/node

In 'Open Graph' section I've tried these combinations (both with Image and Image URL):

[node:field_media_image]
The result is:
<meta property="og:image" content="https://site.commy_image.jpg">

[node:field_media_image:entity:url]
The result is:
<meta property="og:image" content="https://site.com/media/23/edit">

[node:field_media_image:entity:field_media_image:url]
The result is:
<meta property="og:image" content="">

Which token should I use to make it look:
<meta property="og:image" content="https://site.com/sites/default/files/2023_09/image_name.jpg">

πŸ“Œ Task
Status

Active

Version

2.0

Component

Documentation

Created by

πŸ‡¬πŸ‡ͺGeorgia almador

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @almador
  • πŸ‡¬πŸ‡ͺGeorgia almador

    It looks like providing:
    [node:field_media_image:entity:field_media_image]
    at 'Advanced -> Image' and 'Open Graph -> Image' did the trick!

  • πŸ‡ΊπŸ‡ΈUnited States DamienMcKenna NH, USA

    Thanks for working through it and finding the right solution.

    I'm going to turn this into a documentation task to update the module's docs with suggestions on which tokens to use.

  • πŸ‡¬πŸ‡ͺGeorgia almador

    Thanks, Damien!

    I've read somewhere that I need to enable 'Custom display settings' for 'Token' view mode at:
    admin/structure/types/manage/content_type/display

    Is it necessary?

  • πŸ‡ΊπŸ‡ΈUnited States DamienMcKenna NH, USA

    You only need to enable that view mode if you specifically need to customize the output of one of the tokens, so it isn't strictly necessary.

Production build 0.69.0 2024