At the bottom of the colorbox windows, images have their Title text displayed. Is there a way I can set this to be images Alt text instead? I don't mind editing a line of code or two in the module to achieve this.

Comments

frjo’s picture

If the title is empty Colorbox will use the alt instead. If you always want to use the alt you can implement theme_colorbox_imagefield() in your themes template.php file.

Copy theme_colorbox_imagefield() from the colorbox.theme.inc file and change

'title' => $variables['title'],

to

'title' => $variables['alt'],

Remember to clea the Drupal cache so it will pick up the new theme override.

Not tested, this but it should work.

bryancasler’s picture

Making that change didn't actually work, even though it looks like it should. It also produced the following notices.

Notice: Undefined index: alt in theme_colorbox_imagefield() (line 107 of C:\xampp\htdocs\drupal7beta2\sites\all\modules\colorbox\colorbox.theme.inc).
Notice: Undefined index: alt in theme_colorbox_imagefield() (line 107 of C:\xampp\htdocs\drupal7beta2\sites\all\modules\colorbox\colorbox.theme.inc).
Notice: Undefined index: alt in theme_colorbox_imagefield() (line 107 of C:\xampp\htdocs\drupal7beta2\sites\all\modules\colorbox\colorbox.theme.inc).
frjo’s picture

My bad, $variables['image']['alt'] it should be.

bryancasler’s picture

Thanks so much for helping me with this, #3 seems to have solved the issue half way.

When I have an image upload field and the display is set to colorbox, then this works. When I have an image upload field that is used in combination with the Insert module, this does not work. For some reason the colorbox image field styles when inserted are still using the title and not the alt text.

frjo’s picture

Images placed with the insert module uses separate functions.

Copy the "colorbox-insert-image.tpl.php" file to your own theme and where it says title="__title__" change it to title="__alt__".

bryancasler’s picture

Copying the tpl file to my theme and altering it didn't work. However, altering the original tpl file does work. Not sure why that is. Thanks for all your help, it's much appreciated frjo.

frjo’s picture

@animelion, did you clear the Drupal cache after you placed a copy of "colorbox-insert-image.tpl.php" file in your own theme?

The problem with editing the original file is that it will be overwritten next time you update the Colorbox module.

bryancasler’s picture

Just tried it again to make sure, same results.

frjo’s picture

It does work, I just tested it. There is catch however that I had not considered before.

I guess you are using the default admin theme "Seven"? When you add/edit nodes your are using the admin theme so Drupal is looking there for template files.

So adding a copy of "colorbox-insert-image.tpl.php" to "/themes/seven" work but that may also easily get deleted next time you update Drupal core.

The insert module itself must have the same problem, I see if there are any talk there how to solve this.

bryancasler’s picture

That makes sense! Thanks for helping me dance around this issue :)

frjo’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

woop_light’s picture

Has this changed in more recent releases of colorbox? I tried following the instructions of overriding the , but couldn't get it to work (no errors or anything, just didn't have any impact). Also, just for testing, I went into the colorbox.theme.inc code and changed the caption section to read

if (!empty($image['alt'])) {
  $caption = $image['alt'];
}

Surprisingly, that didn't have any effect either.

Any help would be much appreciated. The case | switch that I removed when I put that code in there made it seem like there was an option I could select case 'alt' somehow, rather than case 'auto', but I could be totally off here.


switch ($settings['colorbox_caption']) {
	 case 'auto':
		// If the title is empty use alt or the node title in that order.
		if (!empty($image['title'])) {
			$caption = $image['title'];
		}
		elseif (!empty($image['alt'])) {
			$caption = $image['alt'];
		}
		elseif (!empty($node->title)) {
			$caption = $node->title;
		}
		else {
			$caption = '';
		}
		break;
	case 'title':
		$caption = $image['title'];
		break;
	case 'alt':
		$caption = $image['alt'];
		break;
	case 'node_title':
		$caption = $node->title;
		break;
	case 'custom':
		$caption = token_replace($settings['colorbox_caption_custom'], array('node' => $node));
		break;
	default:
		$caption = '';
}
hass’s picture

Version: 7.x-1.0-beta2 » 7.x-2.4
Category: support » bug
Status: Closed (fixed) » Needs review

If we render a field and "auto" is used we are using ALT if there is not TITLE. Insert should follow the same logics like a field. Aside of this I have now hundreds of images in wysiwyg content without an title defined. Can we read the alt from the image via JS, please?

hass’s picture

Status: Needs review » Active
frjo’s picture

Status: Active » Closed (duplicate)