Support

Account

Home Forums Add-ons Gallery Field Add videos on ACF Gallery

Solving

Add videos on ACF Gallery

  • Hello,

    I use ACF Gallery for my portfolio website and I would like to add some videos in this gallery. I want to keep the possibility to manage the order of my medias, to mix videos and images. I’m not sure if I can add video between my images with the ACF Gallery plugin. How can I do ?

    The current code I use for my gallery :

                <div class='gallery'>
    
                <?php 
    
                $images = get_field('images_projet');
    
                if( $images ): ?>
                    <?php foreach( $images as $image ): ?>
                        <?php $pb = $image['height'] / $image['width']; ?>
    
                        <div class="img-wrapper">
                            <div class="pb" style="padding-bottom: <?= $pb * 100 ?>%;"></div>
                            <img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" />
                        </div>
                        <?php echo $image['caption']; ?>
                    <?php endforeach; ?>
                <?php endif; ?>
    
            <div>

    Thank you
    N.

  • The ACF Gallery field does images only.

    For a mixed gallery of any kind I would suggest using a repeater field with a selection for what type of media and then conditional fields for images and other media types based on this.

  • Thank you for you answer. Sorry, I’m a beginner.

    I added two different repeaters, one for my images, and one for my videos. How can I to the conditional fields after that ?

    Thank you again.

  • In order to loop over them and put them in the right order you will need 1 repeater.

    Then you create a radio field to select media type, for example image or video.

    Then you create a field for adding a video and set the conditional logic to only show when video is selected as media type and an image field that is only shown if image is selected.

  • Hey, do you plan to add support for video in the gallery field? Would be greatly appreciated. All of these workarounds are kind of annoying.

  • Here’s a simple solution:

    
    <?php 
      $images = get_field('gallery');
      foreach( $images as $image ):
      $data_type = pathinfo($image['url'], PATHINFO_EXTENSION);
      if ($data_type == 'mp4') {?>
        <video>
          <source src="<?php echo $image['url'];?>" type="video/mp4">
          Your browser does not support the video tag.
        </video>
      <?php } else {
        echo wp_get_attachment_image($image['ID'], 'large');
      } endforeach; 
    ?>
  • This worked for me, thank you so much!

  • Hi all,

    Just wanted to mention that the Gallery field does indeed support all types of attachments including video files 🙂

  • (posted twice accidentally)

  • Hi Elliot and all – I am uploading mov and mp4’s to a gallery, and it doesn’t display them at all. Is this because I am using the [gallery] shortcode? The code is straigh from the Gallery page examples.

    How can i tweak the code to display videos using the shortcode – or can I?

    Thanks!

Viewing 10 posts - 1 through 10 (of 10 total)

You must be logged in to reply to this topic.