Use Drupal image styles within tokens when creating metatags

By mherchel, 19 May, 2022

Within the Drupal Metatag module, you frequently want to assign images to the og:image or twitter:image metatags. However, you don't want to serve the original image.

You can chain the image style after the image token to serve an image style.

Replace field_image with your image field machine name, and replace my_custom_image_style with the machine name of your image style. This works for image fields and media fields.

            
            [node:field_image:my_custom_image_style:url]

Alt text:
[node:field_image:alt]