skip to Main Content

In Drupal 9, We have a image field in the content types where we have a option to provide values for alt and title attributes. These values will be used for SEO improvements.

Is there any way or modules available to auto pull content title value for image alt and title attributes? Something like token replacements.

Thanks in advance.

Below is the screenshot for the expectation.
enter image description here

2

Answers


  1. Chosen as BEST ANSWER

    imagefield_tokens module helps to accommodate this requirement.

    • Add an 'image' field type to any content entity type (node, taxonomy, etc...)
    • Set Form Display 'Image Field Tokens'
    • Set Display format 'Image Field Tokens'
    • Save changes.
    • Create a new content or change existing content entity.
    • Select image in entity edit form.
    • Fill 'Title and 'Alt' fields for the image using available tokens from the form 'Browse available tokens.'
    • Save changes.

    Note: In Image - Manage Field - Configure default value as [node:title] to get Content title value in image alt and title attributes.


  2. Yes, you can use the token module to see the site tokens in a user interface by going to: admin/help/token

    So the token value for the alt field would be something like:

    [node:field_image:alt]

    And for the title:

    [node:field_image:title]

    You can also use them in a custom theme template by using:

    {{ node.field_image.alt }}
    {{ node.field_image.title }}
    

    I find using the Metatag module helpful to achieve what you want to do here.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search