• Hi,

    I saw that Fancybox for WordPress is using image titles to show text on below of the image and I was looking for showing caption text. I searched it and found an old solution. But it wasn’t working. So, I upgraded it to new version of fancybox.

    This code shows caption text instead of title if there is caption text attached to image.

    1) open “/wp-content/plugins/fancybox-for-wordpress/fancybox.php”
    2) find “jQuery.fn.getTitle = function() { …” line(227. line)
    3) change it with below function :

    jQuery.fn.getTitle = function() { // Copy the title of every IMG tag and add it to its parent A so that fancybox can show titles
    	var arr = jQuery("a.fancybox");
    	jQuery.each(arr, function() {
    		var title = jQuery(this).children("img").attr("title");
    		if ( jQuery( this ).children("img").next().hasClass( 'wp-caption-text' ) ) {
    			title = jQuery( this ).children("img").next().text();
    		}
    		jQuery(this).attr('title',title);
    	})
    }

    voila!

Viewing 9 replies - 1 through 9 (of 9 total)
  • Searched forever. Finally found this thread! i wasn’t able to get the above code to work as the class was not being appended to my elements, but it did lead me to the following solution that works for me … and it does not require editing of plugin files …

    Under ‘Extra Calls’ in the FancyBox for WP settings, enable ‘Additional FancyBox Calls’. Enter the following code:

    var arr = jQuery("a.fancybox");
    jQuery.each(arr, function() {
     var title = jQuery(this).children("img").attr("alt");
     beforeLoad: jQuery(this).attr('title',title);
    });

    Note: i’m using WP 3.5 Multisite and a Pinboard child theme (w/ Lightbox disabled)

    Thank you so much for that, UaMV! Simply brilliant.

    Your code works flawlessly. It auto-shows captions instead of titles, BUT I noticed it also shows titles by default anyway (if there is no caption) – THIS IS AWESOME.

    THANK YOU 🙂

    No UaMV, you use the alt instead of the Caption text. This is something else!

    Is it my solution that’s not working on your setup? If so, is something re-setting the alt attribute of your images. I think mine usually fill with caption if no other alt is set.

    UAMV, Thanks! This worked for me. I could not get the info to show up under the photos either. Pasted your code in that box and I am back on track!

    Nice. I’ll have to check it out. Plans to add it to the repository?

    damiroquai, I saw you removed the download link. Argh. Any word from the Fancybox folks?

    Moderator Jan Dembowski

    (@jdembowski)

    Forum Moderator and Brute Squad

    Side note: If you mean this FancyBox for WordPress plugin then you may get more targeted support posting in that plugin’s dedicated support forum.

    http://wordpress.org/support/plugin/fancybox-for-wordpress#postform

    Jan – already looked there, thanks.

    damiroqaui – thanks! I will check it out!

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Show caption text instead of title in Fancybox for WordPress plugin’ is closed to new replies.