Display WordPress Gallery Captions in a Splide Slide
If you're using the Advanced Views Pro plugin, you can create beautiful sliders using Splide and display each image’s built-in WordPress caption below the image. This guide shows you how to set that u
What You’ll Need
An ACF Gallery field named
Gallery
The Advanced Views Pro plugin (for Splide slider support)
Basic familiarity with editing Twig templates
Step 1: Use the Correct Template Structure
In your View, copy the Default template into the Custom template field and modify it as per the below example, with the image_item.caption declaration being the most important part of the Twig code to output the gallery with captions:
<acf-view-66b5d4134a54e class="{{ _view.classes }} acf-view acf-view--id--{{ _view.id }} acf-view--object-id--{{ _view.object_id }}">
{% if gallery.value %}
<div class="acf-view__gallery2 splide">
<div class="splide__track">
<ul class="acf-view__gallery2-list splide__list">
{% for image_item in gallery.value %}
<li class="acf-view__gallery2-item splide__slide">
<img class="acf-view__gallery2-image" src="{{ image_item.value }}" width="{{ image_item.width }}" height="{{ image_item.height }}" alt="{{ image_item.alt }}" decoding="{{ image_item.decoding }}" loading="{{ image_item.loading }}" srcset="{{ image_item.srcset }}" sizes="{{ image_item.sizes }}">
{% if image_item.caption %}<div class="caption">{{ image_item.caption }}</div>{% endif %}
</li>
{% endfor %}
</ul>
</div>
</div>
{% endif %}
</acf-view-66b5d4134a54e>
Key Details
Caption Source: The
{{ image_item.caption }}
tag pulls from WordPress’s native caption field (set in the media library).Splide Structure: The outer wrapper must follow Splide’s structure:
div.splide > div.splide__track > ul.splide__list > li.splide__slide
Conditional Caption: Only renders the
<div class="caption">
if a caption exists.
Step 2: Add Caption Styling (Optional)
You can style the caption by adding this CSS to your theme:
.caption {
text-align: center;
margin-top: 10px;
font-size: 14px;
color: #333;
}
Step 3: Test and Tweak
Go to any post/page using this View.
Add images to the
Gallery
field, and set captions in the media modal.Confirm the captions appear below each image on the front end.
Tweak the CSS or layout as needed.
Tip
Want the captions to overlay the image or appear only on hover? Wrap the image and caption in a container and add CSS for hover transitions or overlays.
Now you’re all set! 🎉 Your Splide slider built with Advanced Views Pro will show clean, captioned images using native WordPress captions.
Last updated