SLB: Tweaking Caption Precedence

By Sol in Lab

I previously outlined how Simple Lightbox generates the caption that is displayed in the lightbox, but after some review, I think a bit of tweaking is in order.

Previously, if the link itself had a title attribute, then that took precedence over everything else.  This makes sense for individual images because a link’s title attribute could only be set manually by a user (WordPress does not set this attribute).  However, there is a bit of inconsistency between individually inserted images and gallery images in that a gallery item’s link does have the title attribute set.  For gallery images, the link’s title attribute is set to the same value as the thumbnail’s title attribute.  As a result, we can no longer depend on a link’s title attribute being manually set.

The simplest solution was to stop checking of the link had a title attribute and just go straight to evaluating the other potential candidates.  The rest of the candidates are all generated by the information you provide via the GUI when inserting an image/gallery, so for the sake of consistency, I’m sticking with those properties.

In addition, the value entered in the Caption field when inserting an image/gallery now has the highest priority.  I think that this provides a clearer connection for users as what they type in the Caption field when inserting the image/gallery will be used as the caption in the lightbox, so there’s no confusion.

Here is the new list of properties used to generate the caption, ordered by precedence:

  1. Caption field from insert image/gallery UI
  2. Title field from insert image/gallery UI
  3. Alternative Text field from insert image/gallery UI
  4. Link text
  5. Link URL (can be disabled in settings)

Update: NextGEN Gallery image properties now supported as well.