2

I am trying to figure out how to add alt image tags to my photos. I was under the impression that the "file name" served as the alt image tag in Craft CMS, but no such alt tags are populating...and furthermore...I really have no idea where I can add them. Can I do this from the assets field?

2

Out of the box, you can use the image "Title" as alt text. Since it is already configured - you don't need to add any additional fields. Then you can output this in your twig template as:

{% set image = image.yourImageField.one() %}
<img src="image.url" alt={{ image.title }}">

For semantics, you may not want to use the "Title" field. Or, you may be using "Title" for something else. In that case, you can add a new text field to your asset called "Alt Text". It will then appear right below "Title" in your image/asset editing dialogue.

{% set image = image.yourImageField.one() %}
<img src="image.url" alt={{ image.altText }}">

enter image description here

| improve this answer | |
  • Thank you very much - one more question if you don't mind. How do I update the twig template? – jason Jul 29 '19 at 20:22

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.