Hi Wilco,
Thanks for the suggestion. I checked this with FooGallery v3.3.3. The attachment Title, Caption and Alt Text are separate caption sources, and the requested title already works when the lightbox is configured to use the attachment title.
Please edit the gallery and go to Lightbox → Captions, then set:
– Captions Enabled: Enabled
– Caption Source: Override
– Override Caption Title: Attachment Title
Save/update the gallery and clear any page cache. I verified that this outputs the attachment title for the built-in FooGallery lightbox.
We would not want to make Alt Text automatically fall back to the filename/title, because empty alt text can be intentional and has a specific accessibility meaning.
If the title still does not appear, please share your FooGallery version, which lightbox is selected, and a screenshot of the Lightbox → Captions settings so we can check the exact setup.
Thanks Bradvin,
We are using the latest version 3.3.3.
I checked with FooGallery Lightbox and it works indeed.
But the end user has made more then 1000 galleries using the Foobox type with caption set as Smart. I tried many other override settings, but could not get the any captions with the images.
Can you help us further on this?
Best regards,
Wilco
Yes sure. Here is a temporary workaround we tested with FooGallery 3.3.3 and FooBox 2.8.5.
Add this as a PHP snippet using the Code Snippets plugin, or add it to your child theme’s functions.php file:
/**
* Temporary workaround for FooGallery + FooBox Smart caption titles.
* Remove after updating to a FooGallery release containing the permanent fix.
*/
add_filter(
'foogallery_attachment_html_link_attributes',
static function ( $attributes, $args, $attachment ) {
global $current_foogallery;
if (
! is_object( $current_foogallery ) ||
'foobox' !== ( $current_foogallery->lightbox ?? null ) ||
! is_object( $attachment ) ||
array_key_exists( 'data-caption-title', $attributes ) ||
empty( $attachment->title )
) {
return $attributes;
}
$attributes['data-caption-title'] = foogallery_sanitize_full( $attachment->title );
return $attributes;
},
30,
3
);
The snippet only affects galleries using FooBox. It supplies the attachment title when no caption title is already present, so it will not overwrite an explicitly configured caption or modify the image’s Alt Text.
We have tested this successfully in a browser. The permanent fix is also prepared and under review, but we cannot promise a release date yet. Please remove this snippet after updating to a FooGallery release that includes the fix.
Hi Bradvin,
Thanks for the PHP snippet. I tested it successfully!
Best regards,
Wilco