Thanks @kerec. I already have a similar javascript solution in place. I’m hoping for a way to do it without the JS setting. The title and alt should be different in most cases. Right now I have to use my alt like a title. Hoping to avoid that.
With JS, perhaps you could create your titles from custom attributes, a bit like here, only setting the attr ?
Not sure if it help, but I would use the “cleaner_gallery_image” filter to add the image title attribute:
/* Filter the gallery images with user options. */
add_filter( 'cleaner_gallery_image', 'lw_add_title_tag_image', 10, 2 );
/**
* Filters the gallery image if it has a link and adds the appropriate attributes for the lightbox
* scripts.
*
* @since 0.9.0
* @access public
* @param string $image
* @param int $id - the attachment ID
* @param array $attr
* @param int $instance
* @return string
*/
function lw_add_title_tag_image( $image, $id ) {
$attachment_title = get_the_title($id);
$image = str_replace( '<img ', '<img title="' . $attachment_title . '" ' , $image );
return $image;
}
Thanks @landwire. That looks like it should work. The str_replace isn’t my favorite method, but it would accomplish the goal. Thanks for sharing.