WordPress.org

Ready to get started?Download WordPress

Forums

Show caption text instead of title in Fancybox for WordPress plugin (10 posts)

  1. tarikozket
    Member
    Posted 1 year ago #

    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!

  2. UaMV
    Member
    Posted 1 year ago #

    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)

  3. thescarletfire
    Member
    Posted 1 year ago #

    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 :)

  4. danger89
    Member
    Posted 10 months ago #

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

  5. UaMV
    Member
    Posted 10 months ago #

    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.

  6. PTPGmail
    Member
    Posted 9 months ago #

    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!

  7. UaMV
    Member
    Posted 9 months ago #

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

  8. bronw3n
    Member
    Posted 9 months ago #

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

  9. 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

  10. bronw3n
    Member
    Posted 9 months ago #

    Jan - already looked there, thanks.

    damiroqaui - thanks! I will check it out!

Topic Closed

This topic has been closed to new replies.

About this Topic