Support

Account

Home Forums ACF PRO Display ACF Gallery with a unique shortcode for each Gallery instance

Unread

Display ACF Gallery with a unique shortcode for each Gallery instance

  • Can anyone tell me how to display multiple ACF galleries per page with a dynamic shortcode ?

    I have a Text Field named – ‘slider_name’ and wanted to use that to identify each carousel using a shortcode in the page editor.

    I’ve googled this for days and tried many code examples , but i cannot work out how to place a Gallery with a unique shortcode for each gallery instance.

    My Fields

    My Fields

    My code

    <?php
    
    function acf_gallery ( ) {
    
      if (is_singular() ) {
    
        $images = get_field('slider_image_center');
    
        if( $images ): 
          
              if( get_field('slider_image_center_title') ): ?>
                <div class="carousel-title"><?php the_field('slider_image_center_title');?></div>
              <?php endif; ?>
            
              <div class="center-mode">
                  
                  <?php foreach( $images as $image ): ?>
                      
                      <div class="slick-container">
                        <a href="<?php echo $image['url']; ?>" alt="<?php echo $image['title']; ?>" >
                          <!-- To use lazy loading, set a data-lazy attribute on your img tags and repalce the <img src= with <img data-lazy= -->
                          <img data-lazy="<?php echo $image ['sizes']['carousel']; ?>" alt="<?php echo $image['title']; ?>"/>
                        </a>
                      </div>
                  
                  <?php endforeach;?>
              
              </div>
    
        <?php endif; 
          
      }
    
    }
Viewing 1 post (of 1 total)

The topic ‘Display ACF Gallery with a unique shortcode for each Gallery instance’ is closed to new replies.