Skip to content

Instantly share code, notes, and snippets.

@wplit
Created July 30, 2025 00:40
Show Gist options
  • Select an option

  • Save wplit/1856191789df54ab049db7e60aeaf1c9 to your computer and use it in GitHub Desktop.

Select an option

Save wplit/1856191789df54ab049db7e60aeaf1c9 to your computer and use it in GitHub Desktop.
custom function for gallery image count
<?php
function acf_gallery_count($field_name, $post_id = null) {
$gallery = get_field($field_name, $post_id);
$count = is_array($gallery) ? count($gallery) : 0;
return $count;
}
@wplit
Copy link
Author

wplit commented Jul 30, 2025

remember to add the function name to the list of allowed custom functions - https://academy.bricksbuilder.io/article/filter-bricks-code-echo_function_names/

add_filter( 'bricks/code/echo_function_names', function() { return [ 'acf_gallery_count', ]; } );

@wplit
Copy link
Author

wplit commented Jul 30, 2025

Then use within the echo function, replacing 'gallery' with your field name

{echo:acf_gallery_count('gallery')}

SCR-20250730-jtwx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment