Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8566129
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:35:08+00:00 2026-06-11T17:35:08+00:00

I’m developing a WordPress theme and built the Fancybox lightbox plugin into my code.

  • 0

I’m developing a WordPress theme and built the Fancybox lightbox plugin into my code. This works fine, except from one tiny problem.

But I’ll show you the code first, so it is easier to explain.

<dl class='gallery-item'>
    <dt class='gallery-icon'>
        <a href='image.jpg' title='something'><img width="150" height="150" src="image.jpg" class="attachment-thumbnail" title="something" /></a>
    </dt>
    <dd class='wp-caption-text gallery-caption'>
        Description, that should be displayed as title...
    </dd>
</dl>

This is the output of one gallery item of the WordPress standard gallery. What I want to do, is attaching the description in the dd-tags to the lightbox image title (at ht emoment the title of the a-tag is being displayed and that is an alphanumeric string – not very user friendly).

In order to assign something to the lightbox title, the following javascript has to be called in the initialization-function of the lightbox. (This code actually assigns the content of the first .wp-caption-text element to every single image title.)

$(document).ready(function(){
    $("a[href$='.jpg'],a[href$='.png'],a[href$='.gif']").attr('rel', 'gallery').fancybox({

    beforeLoad: function(){
        var caption = $('.wp-caption-text').html();
        this.title = caption;
        }
    });
});

The above code works as expected, but this means, that only the first element with the class wp-caption-text will be assigned to the lightbox and to every single image. But I want to get only the respective wp-caption-text for the image, that has been opened in the lightbox. So I will have to use something like $(this) and then navigate to the corresponding wp-caption-text and assign the text to the caption variable.

I’m struggling with the last point and hope, you can help me. This should not be too difficult, but I don’t have a clue at the moment.

Thanks
Lukas

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T17:35:09+00:00Added an answer on June 11, 2026 at 5:35 pm

    This will be stable if the markup changes. If this doesn’t work it means that this isn’t quite what we expect it to be and we need to figure out what it is. Also notice that I’m using .text() instead of .html(). If you decide to add some markup inside of .wp-capition-text (for example, an icon or something), this will still just grab the text.

    var caption = $(this.element).closest('.gallery-item').find('.wp-caption-text').text();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
Does anyone know how can I replace this 2 symbol below from the string
I am currently running into a problem where an element is coming back from
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.