Use title tag of img as caption if title of a href is not available?

Forums Forums Slimbox2 plugin Use title tag of img as caption if title of a href is not available?

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #639
    lemontea
    Member

    The current one takes the title tag inside the ahref as captions. I was wondering if it’s possible to take the title tag of the img tag if there’s no title tag in the ahref? Because using the WP default upload function, the title tag doesn’t appear in the ahref but the img instead.

    Is that possible? <img decoding=” title=”Smiley” />

    #5352
    malcalevak
    Moderator

    Yes, I believe it is possible, but I’d need to look up the code to modify it to accommodate for this.

    #5353
    lemontea
    Member

    Right, hopefully this feature will be implemented in the future. Thank you so much, this plugin is great! <img decoding=” title=”Smiley” />

    #5354
    Anonymous
    Member

    Any progress on this? I constantly run into this issue because I like to spread out the pictures in my posts rather than group them together in a gallery so I have to go in and manually add title="whatever" to all my <a> image links. I was going to dive into the code and try to figure that out, but just wondering if someone has already done it so I do not have to reinvent the wheel <img decoding=” title=”Smiley” />

    #5355
    malcalevak
    Moderator

    I unfortunately haven’t had much time to do any work on the plugin, though I want to say that I believe the javascript’s API does support this. You can check on the developers site if you like.

    In the meantime, I’ve really been hoping to find the time to work on the plugin.

    #5356
    Anonymous
    Member

    Ok, I found this:
    http://groups.google.com/group/slimbox- … 9d7b06b87#

    So, looks like it is possible to use the alt (or possible even title) tag of the image instead of the title tag of <a>.
    However, I cannot find the snippet of code mentioned in that post anywhere in wp-slimbox2 directory. What am I missing?

    #5357
    Anonymous
    Member

    Using that code you linked to from the Google group, I think I have this working. Not tested properly though, so all feedback appreciated!

    You need to edit the slimbox2_autoload.js.php file in the javascript folder. Around line 16 you will see an if and else where $autoLoad is set. In both branches, change the parameters for the call to slimbox as follows:

    change the bit .slimbox(options, null, function(el)
    to .slimbox(options, linkmapper, function(el)

    Then you need to add a simple linkmapper function to the file to get things working. I added in the following lines just under the if else branch, above the echo where the main jQuery(function($){ is output:

    //#function to use titles from images as slimbox captions
    echo ‘
    function linkmapper(el) {
            return [el.href, el.title || el.firstChild.alt];
    }
    ‘;

    Hope this works for others and helps you out <img decoding=” title=”Smiley” />

    #5358
    Anonymous
    Member

    Small typo in my last post. I’d copied the function direct from the Google thread where the alt attribute was wanted as the caption. Here we’d like the image title attribute instead so the function should be:

    return [el.href, el.title || el.firstChild.title];

    #5359
    malcalevak
    Moderator

    Thanks for figure that out, Janine. Looking it over, it appears sound, though I haven’t tested it myself.

    I’ve been so ridiculously busy with my real job that I just haven’t had time to work on WP-Slimbox2.

    I’m hoping to get some time to work on the successor to the plugin, and also a maintenance release incorporating your suggestion as well as a few others.

    Thanks again for figuring this out.

    #5360
    Anonymous
    Member

    Janine,

    I made the changes last night and got it to work for me as well. Thanks a lot!

    Dima

Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.