13th Sep '23
/
1 comment

nth image from ACF Gallery in Bricks

A user asks:

Good day, do you have in Brickslabs any code available how I could get the second image of an ACF gallery within a Bricks dynamic shortcode?

This Pro tutorial shows how we can set up a custom function that can be called as a Bricks dynamic data tag whilst passing in the name of a Gallery-type of ACF Pro custom field and the number so that the specified nth image can be used as the source or background of an Image element.

After implementing the tutorial, to pull the second image of a page_gallery custom field for example:

{echo:bl_get_nth_image_from_gallery(page_gallery, 2)}

Step 1

Add the following in child theme's functions.php or a code snippets plugin:

This is a BricksLabs Pro tutorial.

For full access login below or create your BricksLabs Pro account

Get access to all 610 Bricks code tutorials with BricksLabs Pro

Related Tutorials..

Pro
Conditional Output based on Date Time Picker Field in Bricks

Conditional Output based on Date Time Picker Field in Bricks

In the past, we showed how elements can be conditionally output based on a post's Date type of ACF field here. This Pro tutorial for…
Categories:
ACF Checkbox Items with Custom SVG Bullets in Bricks

ACF Checkbox Items with Custom SVG Bullets in Bricks

We walk through outputting list items with SVG icons based on the choice of a ACF Checkbox field.
Categories:
Tags:
Accessing ACF Repeater Sub Fields Programmatically in Bricks Query Loop

Accessing ACF Repeater Sub Fields Programmatically in Bricks Query Loop

It is possible to output sub field's values when a Bricks query loop's type has been set to a ACF Repeater without writing code. This…
Categories:
Color Custom Field as Section Background Color on Category/Term Archives in Bricks

Color Custom Field as Section Background Color on Category/Term Archives in Bricks

How to use a color from a taxonomy term custom field for as the hero section background color on archive pages.
Categories:
Tags: