Hi

I'd like to use the Node title as the Alt tag of an imagecache image.

Is it possible?

Tom

Comments

velocis’s picture

Title: Using the Node Title as the Alt tag » Using the Node Title as the Alt tag - One solution

I had a requirement for one of my sites to render all ALT tags on images with the node title. The site used a combination of drupal taxonomy rendered content and views rendered content.

Found the function theme_imagecache_formatter_imagelink in /imagecache/imagecache.module.php
and after the section

  $item = $element['#item'];
  $item['data']['alt'] = isset($item['data']['alt']) ? $item['data']['alt'] : '';
  $item['data']['title'] = isset($item['data']['title']) ? $item['data']['title'] : NULL;

and added the following:

if ( !empty( $element['#node']->title) ) {
  		$item['data']['alt'] = check_plain($element['#node']->title);
  }else{
  		$item['data']['alt'] = check_plain($element['#node']->node_title);
  }

It now generated alt tags for both views and other content

I also applied this same method to two other functions within the same file
- theme_imagecache_formatter_linked
- theme_imagecache_formatter_imagelink

Branndon’s picture

Logged in just to say thanks! This helped me.

fizk’s picture

Status: Active » Closed (fixed)

Please reopen if this is still an issue with ImageCache 6.x-2.0-rc1.