Drupal image assist force a default alt tag
Mike Dixon
We make heavy use of the Drupal image assist module (or img_assist as its known) - but find that its handling of empty alt tags is quite poor. The problem being that if when inserting the image the user does not specify a caption or description then the alt (and title) attributes are both empty.
This is clearly not ideal on a modern standards compliant site - luckily the solution to the image assist alt tag problem is a little theme override.
function phptemplate_image_display($node, $label, $url, $attributes) {
if (!$node->title){
$node_temp = node_load($node->nid);
$node->title=$node_temp->title;
}
return theme('image', $url, $node->title, $node->title, $attributes, FALSE);
}
We do a quick check to see if the title of the node has been emptied (typically by the image assist module, but it could be from somewhere else) - and if it has we reload the node (don't worry, it's cheap as Drupal caches these for us) and reset our title. This title is then passed into the image theme and is used as the alt and title text for the image.