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


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'>
                $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']; ?>" />
                        <?php echo $image['caption']; ?>
                    <?php endforeach; ?>
                <?php endif; ?>

    Thank you

  • 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:

      $images = get_field('gallery');
      foreach( $images as $image ):
      $data_type = pathinfo($image['url'], PATHINFO_EXTENSION);
      if ($data_type == 'mp4') {?>
          <source src="<?php echo $image['url'];?>" type="video/mp4">
          Your browser does not support the video tag.
      <?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?


  • Also looking for a solution to this problem.

  • Me too! I look all around and didn’t find a way to mix videos and photos.

    The workaround of the repeater and a radio checkbox to select video or image… couldn’t make it work.

    I see that the gallery field allows loading video, but can’t figure out how to output them. i can only see the images, and the blank space with the url of the video, when I click on it, it just says “the image could not be loaded”.

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

The topic ‘Add videos on ACF Gallery’ is closed to new replies.