Home › Forums › Pro Support › Add Text on Image lightbox
- This topic has 5 replies, 2 voices, and was last updated 2 years, 3 months ago by
elvin.
-
AuthorPosts
-
February 16, 2021 at 3:59 am #26858
Andreas
ParticipantHi,
There is any way when i have enabled the image lightbox to display some more info of the post there?
If there is any chance for acf fields or simple text please i would really apreciate that if is possible
February 16, 2021 at 7:36 am #26868elvin
ModeratorHi,
I’m not sure I fully get what you mean but perhaps what you’re trying to achieve is similar to this:
https://wpshowposts.com/support/topic/add-title-to-image-lightbox/page/2/#post-26221Give it a try and let us know how it goes. 🙂
February 16, 2021 at 7:50 am #26873Andreas
ParticipantHi Elvin i saw this post,
Yes is something like that except of custom text in each post.
February 16, 2021 at 8:46 am #26877elvin
ModeratorWe can assign the custom field as
<a>
tags attribute by using thewpsp_image_data
filter.add_filter('wpsp_image_data',function(){ $field = get_field('your_acf_field_slug'); return 'slick-caption="'.$field.'"'; });
This will add
slick-caption="[acf_field_value]"
. We can fetch this as the caption for the featherlight image.After applying this filter, we can modify the script to take the
slick-caption
attribute value.add_action( 'wp_footer', function () { ?> <script> jQuery( document ).ready( function( $ ) { $.featherlightGallery.prototype.afterContent = function() { var caption = this.$currentTarget.find('img').parent().attr('slick-caption'); this.$instance.find('.caption').remove(); $('<div class="caption">').text(caption).appendTo(this.$instance.find('.featherlight-content')); }; } ); </script> <?php } );
February 16, 2021 at 9:02 am #26879Andreas
ParticipantHey Elvin that was epic !
It displays the caption with the custom field but not in the lightbox but insted over the image in the related posts
You can see here , this li elements are the custom fields – > https://active-energy.bee.backtobuzz.com/v1/trinasolar/tsm-deg18mc-20ii-475wp-505wp/
There is any hook to put them inside the lightbox?
Once again thank you a ton man!
February 16, 2021 at 7:04 pm #26900elvin
ModeratorThere is any hook to put them inside the lightbox?
There’s no hook within the lightbox gallery as the gallery img itself is generated by a script.
I don’t think the previously provided solution would work well if the
$field
you have outputs an unordered list rather than a simple text caption string. The filter snippet was made for simple text strings for captions, not for inserting HTML structure.In that case, I think we need to do something else.
Try doing this:
Instead of inserting it as an attribute, lets hook it in on
wpsp_inside_image_container
as a content.add_action('wpsp_inside_image_container',function(){ $field = get_field('your_acf_field_slug'); echo $field; });
After hooking it in, we can modify the script to fetch your unordered list and append it as caption.
add_action( 'wp_footer', function () { ?> <script> jQuery( document ).ready( function( $ ) { $.featherlightGallery.prototype.afterContent = function() { var caption = this.$currentTarget.find('img').parent().prev(); this.$instance.find('.caption').remove(); $('<div class="caption">').html(caption).appendTo(this.$instance.find('.featherlight-content')); }; } ); </script> <?php } );
After this, we may have to style it with CSS. Let me know once you’ve done this so I could check and help out with the CSS write up.
-
AuthorPosts
- You must be logged in to reply to this topic.