ACF Pro Gallery and Image Shortcodes

I have added the shorctcode for acf_gallery to my Pro child theme, yet it is not displaying.

I also wish to add an acf_image shortcode, but am at a loss as the code provided on this forum (see below), is not displaying my gallery.

Please advise what I have done wrong… with recommendation/solution to my newbie question

// ACF Gallery Shortcode
// =============================================================================

add_shortcode(‘display_acf_gallery’, ‘acf_gallery’);

function acf_gallery ( $atts ) {

if ( empty ( $atts[‘name’] ) ) return “”;

$images = get_field( $atts[‘name’] );

if( $images ): ?>


    <?php foreach( $images as $image ): ?>


  • <?php echo $image['alt']; ?>

    <?php echo $image['caption']; ?>



  • <?php endforeach; ?>
<?php endif; }

Hi,

You can try this code instead.

// ACF Gallery Shortcode
// =============================================================================

add_shortcode('display_acf_gallery', 'acf_gallery');

$images = get_field('gallery');

if( $images ): ?>
    <ul>
        <?php foreach( $images as $image ): ?>
            <li>
                <a href="<?php echo $image['url']; ?>">
                     <img src="<?php echo $image['sizes']['thumbnail']; ?>" alt="<?php echo $image['alt']; ?>" />
                </a>
                <p><?php echo $image['caption']; ?></p>
            </li>
        <?php endforeach; ?>
    </ul>
<?php endif; ?>

For more information, kindly refer to the link below

Hope that helps.

Thanks Paul, tried without success, and have looked at that ACF link many times without any revelation, in part because of the use of the word “gallery” confuses me.

In my ACF Field Group I have 2 fields that I have set to Gallery Field type one named estimate, the other photo_evidence

and currently using the shortcodes

[acf_gallery=“estimate”]

[acf_gallery=“photo_evidence”]

in my post, but the contents is not displayed, I am sure I am doing something obvious wrong…unfortunately…I can’t see it yet

Thanks for your patience

Hi There,

Would you mind providing us with login credentials(by clicking on the Secure Note button at the bottom) so we can take a closer look? To do this, you can make a post with the following info:

  • Link login to your site
  • WordPress Admin username / password

Thanks.

Sorry for the delay I had been testing on my localhost so I had to repeat on a live server

This is what I get with ACF PRO

http://intraconis.com/?p=30121

This is what I am currently getting using Gravity Forms and Gravity View, which is a sledge hammer to crack a nut

http://intraconis.com/?p=30103

Looking forward to resolving this

Best regards & thank you

Hi @Fairbanking

The code you need to add to your child theme is like that:

add_shortcode('display_acf_gallery', 'acf_gallery');

function acf_gallery ( $atts ) {

if ( empty ( $atts['name'] ) ) return "";

$images = get_field( $atts['name'] );

if( $images ): ?>

    <?php foreach( $images as $image ): ?>
                <a href="<?php echo $image['url']; ?>">
                    <div class="thumbnail" style="float:left;" ><img src="<?php echo $image['sizes']['thumbnail']; ?>" alt="<?php echo $image['alt']; ?>" /></div>
                </a>
    <?php endforeach; ?>

<?php endif; 

}
  

I’ve already added this to you.

Also, this is how you can use shortcodes:

[display_acf_gallery name="estimate"]

[display_acf_gallery name="photo_evidence"]

I’ve already corrected that on this page and as you can see the images are now appearing fine:
http://intraconis.com/?p=30121

However, I have no idea what are these line of codes appearing at the bottom of this page, it has nothing to do with the custom code I added to functions.php file.

Thanks.

Thanks so much, those extraneous lines of code were as a result of me following the instructions to modify my wp-single, I must have misunderstood them.

I had hoped to also have an ACF Image Shortcode to give me a clearer understanding of how to construct other Shortcodes for the other types of Fields.

Indeed I would have thought that this would have been a really useful thing for Themeco to provide them, once and for all through the Knowledgebase which I spent hours trying to understand… and clearly failed.

Thanks again, but it would be really helpful to have those shortcodes

John

You’re most welcome John.

This is something we can add to our list of feature requests. This way it can be taken into consideration for future development. All of these items are discussed with our team internally and prioritized based on the amount of interest a particular feature might receive. Thanks!

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.