Control Captions with ACF
-
I have the plugin working well with images loaded to a repeater. The images show along with their captions. If there are no captions with an image it appears to put in the image title. I was hoping for more control over this. I have a field in my repeater to write a caption. My goal is to override the caption associated with the image or the title and use the caption entered in ACF. Is there some way to do this?
-
Hi @lutzcreativegroup,
sorry for the delay.Since your are using Advanced Custom Fields instead of a native WordPress Gallery the support I can provide here is limited.
I suggest you to check the filter
slick_slider_caption_html(see https://ww.wp.xz.cn/plugins/slick-slider/#faq, question “Is it possible to adjust the caption’s markup?”). For simple usage example, please refer to https://ww.wp.xz.cn/support/topic/dont-fallback-to-title-if-caption-is-blank/#post-8747666,I hope this helps.
Hi @lutzcreativegroup,
have you been able to review my response? I’d really like to see this thread resolved.Sorry, I was exploring other options. The filter you shared does get rid of the titles and only shows the captions associated with the image in the Media Library. This is good, but not exactly what I am trying to accomplish.
Using ACF, I have a method of adding/organizing photos for a slider. It also allows me to enter an Alternative Caption that would override the caption in the Media Library.
So I loop through the entries and then populate your shortcode:
$GalleryCode.=do_shortcode('[gallery slick_active="true" sl_show_caption="true" sl_dots="true" sl_fade="true" type="slideshow" size="large" sl_autoplay="true" ids="'.$GalleryID.'"]');I then return $GalleryCode. So I am lookng for a way to insert an alternative caption per slide vs a filter that tells the system to show nothing if there is no slide associated with the image in the Media Library.
Here is my complete shortcode:
function jmore_gallery(){ if( have_rows('galleries') ){ $GalleryCode='<div id="GalleriesContainer">'; while( have_rows('galleries') ): the_row(); $GalleryCounter=$GalleryCounter+1; $GalleryID="custom-".$GalleryCounter; $GalleryTitle=get_sub_field('gallery_title'); $GalleryArray=array(); $CaptionArray=array(); $GalleryCode.='<h2>'.$GalleryTitle.'</h2>'; $GalleryCode.='<div class="IndividualGalleryContainer">'; if( have_rows('image_gallery') ){ while( have_rows('image_gallery') ): the_row(); $ThisImage=get_sub_field('image'); $ThisImageShowCaption=get_sub_field('show_caption'); $ThisImageAltCaption=get_sub_field('alternative_caption'); $ThisImageID=$ThisImage['id']; array_push($GalleryArray, $ThisImageID); $ThisImageURL=$ThisImage['url']; if($ThisImageShowCaption==1){//If captioning is turned on for this image if(!empty($ThisImageAltCaption)){//Check if there is an Alternative caption added $ThisImageCaption=$ThisImageAltCaption;//Puts the alternative caption in to the variable $ThisImageCaption=str_replace(",",",",$ThisImageCaption);//Replaces commas with HTML character equivelant }else{ $ThisImageCaption=$ThisImage['caption'];//Use caption associated with image from library $ThisImageCaption=str_replace(",",",",$ThisImageCaption);//Replaces commas with HTML character equivelant } }else{ $ThisImageCaption=""; } array_push($CaptionArray, $ThisImageCaption); endwhile;//while( have_rows('image_gallery') ): the_row(); } $GalleryIDs=implode(",",$GalleryArray);//Puts a comma after each ImageID except for the last one //$GalleryCode.="Gallery IDs: ".$GalleryIDs."<br>"; $GalleryCaptions=implode(",",$CaptionArray);//Puts a comma after each Caption except for the last one //$GalleryCode.="Gallery Captions: ".$GalleryCaptions."<br>"; //$GalleryCode.=do_shortcode('[soliloquy_dynamic id="'.$GalleryID.'" images="'.$GalleryIDs.'" captions="'.$GalleryCaptions.'"]'); $GalleryCode.=do_shortcode('[gallery slick_active="true" sl_show_caption="true" sl_dots="true" sl_fade="true" type="slideshow" size="large" sl_autoplay="true" link="none" ids="'.$GalleryID.'"]'); //$GalleryCode.=soliloquy_dynamic( array( 'id' => $GalleryID, 'images' => $GalleryIDs ) ); $GalleryCode.='<p> </p></div><!-- /IndividualGalleryContainer -->'; endwhile; // while( has_sub_field('galleries') ) $GalleryCode.='</div><!-- /GalleriesContainer -->'; } return $GalleryCode; } add_shortcode('JmoreImageGallery', 'jmore_gallery');-
This reply was modified 8 years, 5 months ago by
lutzcreativegroup.
By the way, I cannot get the do_shortcode to work with the Slick shortcode.
Don’t worry about this. I managed to get a different plugin to do what I wanted. Thanks for the help though.
Hi @lutzcreativegroup,
I’m glad you where able to solve this.Just for the record: The
[gallery]shortcode is the native WordPress gallery shortcode. Slick Slider simply filters the HTML output. Sodo_shortcode( '[gallery ids="1,2,3"]' );indeed does work (see https://codex.ww.wp.xz.cn/Gallery_Shortcode#Usage). -
This reply was modified 8 years, 5 months ago by
The topic ‘Control Captions with ACF’ is closed to new replies.