Getting alt text to display without a caption using img_assist

Published on the 4th September, 2007

I ran into a spot of trouble recently with img_assist, in that it only displayed alt text if there was also a caption below the image. Img_Assist takes the alt text from a combination of the title and description, and these fields are filled by default from the title and body of the image node. Although there is no real need for a caption below each image, you will almost always need alt text.

The problem was that Drupal wasn't wrapping the caption in a span, which meant no easy way of hiding it without digging into the module code. This is the HTML output:

<img class="image _original" width="200" height="75" title="Sunset" alt="Sunset" src=""/>

It turns out that the HTML filter was set to a lower weight than the inline images filter, so the span was being removed when the page was being processed. To fix this, simply set the HTML filter to something lighter (I set mine to -10) and you'll find the caption is now wrapped in a span. This setting is found in Administer > Site Configuration > Input Formats > Configure Filtered HTML (Or whatever filter you're using) > Rearrange tab. Now you should find that the page displays the caption to accompany the alt text, like this:

<span class="inline none">
<img class="image _original" width="200" height="75" title="Sunset" alt="Sunset"  src=""/>
<span class="caption" style="width: 200px;">

Then, to remove the caption from displaying on the screen, use the following CSS:

span.caption {

I think it's a good idea to run the HTML filter first in general so it cleans the unwanted code up but doesn't also interfere with other filters.

Please feel free to post any comments below.