3

I am using Views to generate an image gallery. Each image is linked to the content the images comes from, but what I would also like is to add alt and/or title attributes to each of the images. How would I go about doing this?

2 Answers 2

4

You can modify the output by selecting the option to re-write output of the field.

Likely, you will want to change the output of your image field from an image to the "URL to file" option. You will also likely need to add other fields to your view (e.g., image title), which you will want to hide (an option in for views fields). Make sure these occur before your image field in the views fields dialog box.

Next you will want to rewrite your image field (check the "Rewrite the output of this field" option for your image field). Views will now show you a box where you can specify the format of your image field, you will likely what to use something such as

<img src="[field_gallery_image_fid]" title="[title]" alt="[title]" />

Views will then replace the [field_gallery_image_fid] macro with the "URL to file" info, and replace the [title] macro with the node title (assuming you added that field ahead of the image field.

In the field rewrite interface views will provide you with a list of macros/fields you can add, all of these fields must occur prior to the field you are rewriting. If you don't want those fields displayed (other than in the rewrite) make sure to check the "Exclude from display" option on a given field.

1
0

Go to each content type having image field used in views :

<YOUR_SITE>/admin/structure/types/manage/<YOUR_CONTENT_TYPE>/fields/<YOUR_IMAGE_FIELD>
Eg : 
/admin/structure/types/manage/gallery/fields/field_gallery_images

Check :

Enable Alt field
Enable Title field

This will provide 2 additional fields on each image to specify the alt and title attributes.
Views will add them automatically.

Credits : http://www.inmotionhosting.com/support/edu/drupal-7/working-with-content/enable-image-alt-text

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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