Home › Forums › Pro Support › Add title to image lightbox
Tagged: lightbox
- This topic has 21 replies, 4 voices, and was last updated 2 years, 7 months ago by
elvin.
-
AuthorPosts
-
November 26, 2020 at 6:32 am #23087
Daniel
ParticipantHi!
Is it possible to add the title of the post below the image in lightbox?
November 27, 2020 at 12:20 pm #23188Tom
KeymasterHi there,
Our lightbox feature using Featherlight: https://github.com/noelboss/featherlight
They provide this solution: https://github.com/noelboss/featherlight/wiki/Gallery:-showing-a-caption
Not sure if it will work – but worth a shot?
Let me know 🙂
November 30, 2020 at 1:28 am #23410Daniel
ParticipantThanks for your help Tom!
Unfortunately the solution you offered me did not work.
http://lagui.es/disenos-puertas/
I understand that this kind of problems are beyond the scope of WPShow Posts.
I was simply asking if there would be any simple solution to apply, but there has been no luck.
It’s really not essential to display the name next to the images in the lightbox.
Thanks anyway.
December 1, 2020 at 10:47 am #23530Tom
KeymasterOnce we update this plugin as a block, we’ll be going with a different lightbox solution. I’ll be sure to implement one that has this ability built in 🙂
December 3, 2020 at 8:22 am #23706Daniel
ParticipantI hope to get a chance to try out that new version as soon as possible.
Regards!December 3, 2020 at 3:28 pm #23726Vlidi
ParticipantHi Tom & WPSP team,
was just browsing the Forum to try to find the solution for captions, and I learn that the block version is coming, yey!
I would like to give the Featherlight code a chance in the meantime, and great that it promises to pull the content from the “alt” tab.
But it gives the following error and Code Snippets kindly refuse to proceed:
Fatal error on line 1:
syntax error, unexpected '.', expecting variable (T_VARIABLE) or '{' or '$'
I see the exact same code working on their demo.
How should I adapt it for GP?Thanks!
December 3, 2020 at 3:42 pm #23730Vlidi
ParticipantP.S.
I am aware that you posted this fix, but I am doing something wrong, as however I replace$
instances, the Code Snippets complains.
And this is where my PHP mastery ends :-/Thanks!
December 4, 2020 at 2:02 pm #23782Tom
KeymasterHi there,
That code is javascript, so it needs to be added in a .js file, or as a snippet like this:
add_action( 'wp_footer', function() { ?> <script>Put it in here</script> <?php } );
January 25, 2021 at 3:16 pm #25920Vlidi
ParticipantHey Tom, thank you!
After a long while of juggling things around – and breaking Code Snippets 🙂 – I finally think I have it assembled properly.
Unfortunately, still no captions.
Can you confirm that the code is OK?
Looks like this now:
add_action( 'wp_footer', function() { ?> <script> jQuery.featherlightGallery.prototype.afterContent = function() { var caption = this.$currentTarget.find('img').attr('alt'); this.$instance.find('.caption').remove(); jQuery('<div class="caption">').text(caption).appendTo(this.$instance.find('.featherlight-content')); }; </script> <?php } );
…and if the code is good, does it mean that there is no way to have captions at all?
Thanks!
January 25, 2021 at 9:01 pm #25924elvin
ModeratorYou can try this code:
jQuery( document ).ready( function( $ ) { $.featherlightGallery.prototype.afterContent = function() { var caption = this.$currentTarget.find('img').attr('alt'); this.$instance.find('.caption').remove(); $('<div class="caption">').text(caption).appendTo(this.$instance.find('.featherlight-content')); }; } );
Note: This will only work if your images have alt texts. If its empty, nothing will display.
Also, you may have to do a bit of CSS to achieve the desired result as because w/o it, the caption will appear below the image.
January 26, 2021 at 4:55 am #25933Vlidi
ParticipantHi Elvin, thank you!
Unfortunately, still no captions.
(I made sure to have something entered in Alt, Description and Caption fields, just in case.)
In addition, the console produces this error:
Uncaught TypeError: Cannot read property 'prototype' of undefined
…pointing to this line:
jQuery.featherlightGallery.prototype.afterContent = function() {
Maybe I messed something up, so here’s the full code I used:
add_action( 'wp_footer', function() { ?> <script> jQuery( document ).ready( function( $ ) { $.featherlightGallery.prototype.afterContent = function() { var caption = this.$currentTarget.find('img').attr('alt'); this.$instance.find('.caption').remove(); $('<div class="caption">').text(caption).appendTo(this.$instance.find('.featherlight-content')); }; } ); </script> <?php } );
Any idea?
Thanks!
January 26, 2021 at 5:07 am #25937Vlidi
ParticipantI have adjusted the snippet a bit like so:
add_action( 'wp_footer', function() { ?> <script> jQuery( document ).ready( function( $ ) { $.featherlightGallery.prototype.afterContent = function() { var caption = this.$currentTarget.find('img').attr('alt'); this.$instance.find('.caption').remove(); $('<div class="caption">').text(caption).appendTo(this.$instance.find('.featherlight-content')); }; </script> <?php } )
…but still the errors appear, and no captions.
January 27, 2021 at 4:33 am #25964elvin
ModeratorTry this:
add_action( 'wp_footer', function () { ?> <script> jQuery( document ).ready( function( $ ) { $.featherlightGallery.prototype.afterContent = function() { var caption = this.$currentTarget.find('img').attr('alt'); this.$instance.find('.caption').remove(); $('<div class="caption">').text(caption).appendTo(this.$instance.find('.featherlight-content')); }; } ); </script> <?php } );
I fixed the missing syntaxes. Here’s an actual demo of it working: WPSP DEMO
You can see the caption in red when you click on the image. Some image don’t have alt text so nothing displays on them.
January 27, 2021 at 6:25 am #25976Vlidi
ParticipantThank you very much, works great 🙂
My last question: any way to display the captions while in Carousel mode, before we enter Lightbox?
WPSP is simply great, very enthusiastic about the block editor version.
And thanks once again for the fantastic support!January 27, 2021 at 11:55 pm #26021elvin
ModeratorMy last question: any way to display the captions while in Carousel mode, before we enter Lightbox?
I’m not exactly sure I get what you mean. Do you have a reference site you’d like to replicate?
-
AuthorPosts
- You must be logged in to reply to this topic.