Hi!
In Customizr (version less than 3.10), the title displayed at the bottom of the Fancybox popin is the post or page title instead of the image title.
To fix this, here’s a quick javascript snippet that displays the image title (or the alt field if there’s no title) for the FancyBox popin title.
Copy this code in your functions.php file :
add_action ('wp_footer' , 'set_fancybox_title'); function set_fancybox_title() { ?> <script id="tc-fancybox-title" type="text/javascript"> jQuery(document).ready(function ($) { $('a[rel*=tc-fancybox-group]').each( function() { var title = $(this).find('img').prop('title'); var alt = $(this).find('img').prop('alt'); if ( typeof title !== 'undefined' && 0 != title.length) { $(this).attr('title',title); } else if (typeof alt !== 'undefined' && 0 != alt.length) { $(this).attr('title',alt); } }); }); </script> <?php }
I hope this will be useful for you guys!
Your comments and improvements are welcome as always.
3 thoughts on “Setting image title (or alt attributes) as the Fancybox pop-in title”
Customizer’s default Lightbox/Fancybox is great! However, I would like the theme to offer some simple/straightforward customizations. For instance, instead of the “img” type content I would like to use the “iframe” type. On “Image Details” I tried “Advanced Options” using class=”grouped_elements” with different rel=”tc-fancybox-group1..2.. 3…” but the fancybox pops-up always the same. Thx you in advance.
Just what I needed, chef. Merci mille fois.
You are welcome @chappie. Glad it helps!