/* Create Shortcode for ACF Gallery || Example with Wordpress Gallery */
function acf_gallery_shortcode() {
$images = get_field( 'gallery' );
$image_ids = array();
if ( $images ) {
foreach ( $images as $image ) {
array_push( $image_ids, $image['ID'] );
}
// Generate string of ids ("123,456,789").
$images_string = implode( ',', $image_ids );
// Generate and do shortcode.
// Note: The following string is split to simply prevent our own website from rendering the gallery shortcode.
$shortcode = sprintf( '[' . 'gallery ids="%s"]', esc_attr( $images_string ) );
echo do_shortcode( $shortcode );
}
}
add_shortcode( 'gallery_acf', 'acf_gallery_shortcode' ); /* Shortcode Name, Functions Name || Use [gallery_acf] */