0

I am using standard WP gallery to display images. I have added caption to every image, image title was not changed so it is same like file name. When I open one image in gallery it shows caption text in span class "TitleText". This is ok but with some images it shows the same text and it display span TitleText and span CaptionText. You can see it here: http://www.tandem.sk/galeria/automobilizmus/cerpacie-stanice/ If you click on first image caption is showing twice, however second image is working fine. The text you see is set as caption in gallery.

Any ideas how to fix this?

2
  • Are you using a plugin to generate the lightbox or is it code that you wrote?
    – Stephen S.
    Commented May 8, 2014 at 16:36
  • I am using wp-jquery-lightbox plugin
    – horin
    Commented May 8, 2014 at 16:47

1 Answer 1

1

It looks like your WP Jquery Lightbox plugin is generating these extra captions.

Check out the source of the jquery.lightbox.js file:

        ... cut ...

        var s = '';
        if (title != '') {
            s = '<span id="titleText">' + title + '</span>';
        } 
        if (caption != '') {
            if (title != ''){
                s += '<br />';
            } 
            s += '<span id="captionText">' + caption +'</span>';
        }           

       ... cut ...

where you can have both a title and a caption for each image.

The title part is picked up from the image link title, the image title or the image alt attribute:

        if (this.title) { //title of link
            title = this.title;
        } else if (jqImg.attr('title')) {
            title = jqImg.attr('title'); //grab the title from the image if the link lacks one
        } else if(jqImg.attr('alt')){
            title = jqImg.attr('alt'); //if neither link nor image have a title attribute
        }

In your case it seems to be the image alt attribute.

If the image caption is equal to the image alt attribute, then you should only get the title part.

So to get rid of the duplications, you make sure the image alt attribute is the same as the image caption. Notice that the comparison is made after this replacement:

    captionText = $.trim(captionText).replace('&#8217;', '&#039;').replace('’', '\''); //http://nickjohnson.com/b/wordpress-apostrophe-vs-right-single-quote
    if (title.toLowerCase() == captionText.toLowerCase()) {
        title = caption; //to keep linked captions
        caption = ''; //but not duplicate the text                              
    }
9
  • so how should i repair it? Use different plugin?
    – horin
    Commented May 8, 2014 at 16:53
  • well it is set in alternative text. I have checked it and it is set exactly the same for working and for not working images
    – horin
    Commented May 8, 2014 at 17:06
  • Look closer, it's a tiny difference ;-)
    – birgire
    Commented May 8, 2014 at 17:08
  • trust me I have looked closer. I have set image title and image caption at every image ... no alt text is set at wordpress and still some images works and some dont
    – horin
    Commented May 8, 2014 at 17:16
  • 1
    yeah it is working without dash ... now I need to determine why wordpress makes this – from this - automatically and how to turn it off
    – horin
    Commented May 8, 2014 at 17:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.