Display WordPress Gallery Captions in a Splide Slide
If you're using Advanced Views Pro, you can create beautiful sliders using Splide and display each image’s built-in WordPress caption below the image.
What You’ll Need
An ACF Gallery field named
GalleryThe Advanced Views Pro plugin (for Splide slider support)
Basic familiarity with editing Twig templates
Step 1: Use the Correct Template Structure
In your Layout, copy the Default template content 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 Layout or theme:
.caption {
text-align: center;
margin-top: 10px;
font-size: 14px;
color: #333;
}Step 3: Test and Tweak
Go to any post/page with this Layout.
Add images to the
Galleryfield, and set captions in the media modal.Confirm the captions appear below each image on the front end.
Tweak the CSS styles as needed.
Now you’re all set! 🎉 Your Splide slider built with Advanced Views Pro will show clean, captioned images using native WordPress Media caption field.
Last updated