# How to make a Slideshow randomize

**URL:** <https://community.elfsight.com/t/how-to-make-a-slideshow-randomize/65371>\
**Category:** Platform Tips\
**Tags:** squarespace\
**Created:** [August 12, 2024, 4:40am UTC](https://community.elfsight.com/t/how-to-make-a-slideshow-randomize/65371 "2024-08-12T04:40:47Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![tuanphan](https://sea2.discourse-cdn.com/flex020/user_avatar/community.elfsight.com/tuanphan/32/3165_2.png) [@tuanphan](https://community.elfsight.com/u/tuanphan)\
**Post date:** [August 12, 2024, 4:40am UTC](https://community.elfsight.com/t/how-to-make-a-slideshow-randomize/65371/1 "2024-08-12T04:40:47Z")

</div>

To make a slideshow randomize in Squarespace, you can follow these steps.  
**#1.** This code supports all types of Gallery Slideshow: **Simple + Full**  
 ![image](https://us1.discourse-cdn.com/flex020/uploads/elfsight/original/3X/7/2/7272b3b970c9f4690016ab129f8a27398647d311.png)

![image](https://us1.discourse-cdn.com/flex020/uploads/elfsight/original/3X/0/f/0fcc25197622aeadd7406a0f1bf77a7add9de3cc.png)

**#2.** First, enable **Slideshow Caption**

 ![image](https://us1.discourse-cdn.com/flex020/uploads/elfsight/original/3X/a/a/aa4b102b6d80c31b0d76e42d7eda8e6b1c7b9836.png)

**#3.** Edit First Image in the Slideshow and add this text to the Description field

```auto
twc-gsior

```

 ![image](https://us1.discourse-cdn.com/flex020/uploads/elfsight/original/3X/a/4/a4b4823815a69dc1635b44f162df9e67d44f6ddf.jpeg)

**#4.** Use this code to Page Header Injection (Page where you use Slideshow)

```auto
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.0/jquery.min.js"></script>
<script>
  $( ( ) => {
  
    /*
    
      gallery section image order random
      
      License : < https://tinyurl.com/s872fb68 >
      
      Version : 0.2.0
      
      SS Version : 7.1
      
      Dependencies : jQuery
      
      By : Thomas Creedon < http://www.tomsWeb.consulting/ >
      
      no user serviceable parts below
      
      */
      
      const version = '0.2.0';
      
      const s = `Gallery Section Image Order Random v${ version }, ` +
      
        'License < https://tinyurl.com/s872fb68 >, ' +
        
        'Tom\'s Web Consulting < http://www.tomsWeb.consulting >';
        
      console.log ( s );
      
    const codeKey = 'twc-gsior';
    
    const selectorPrefix = '.gallery-section ';
    
    const selectorSuffix = ' .gallery-caption ' +
    
      `p.gallery-caption-content:contains(${ codeKey })`;
      
    let selector = selectorPrefix
    
      +
      
      [
      
        '.gallery-fullscreen-slideshow',
        
        '.gallery-grid--layout-grid',
        
        '.gallery-masonry',
        
        '.gallery-reel',
        
        '.gallery-slideshow',
        
        '.gallery-strips--layout-strips'
        
        ]
        
      .join ( `${ selectorSuffix }, ${ selectorPrefix }` )
      
      +
      
      selectorSuffix;
      
    const $elements = $( selector );
    
    if ( ! $elements.length ) return; // bail if no $elements
    
    const $galleries = $elements
    
      .parents ( '.gallery-section' );
      
    let callback = function ( ) {
    
      const $this = $( this );
      
      let text = $this
      
        .text ( )
        
        .replace ( codeKey, '' )
        
        .trim ( );
        
      if ( text )
      
        $this
        
          .text ( text )
          
        else
        
          $this
          
            .parents ( 'figcaption' )
            
            .remove ( );
            
      }
      
    $elements.each ( callback );
    
    callback = function ( ) {
    
      const callback = function ( ) {
      
        const r = Math.floor ( Math.random ( ) * $images.length );
        
        const $image = $images.eq ( r );
        
        $( this )
        
          .append ( $image );
          
        $images = $images.not ( $image );
        
        }
      
      const selector = [
      
        '.gallery-fullscreen-slideshow-item-img',
        
        '.gallery-grid-item-wrapper',
        
        '.gallery-masonry-item-wrapper',
        
        '.gallery-reel-item-src',
        
        '.gallery-slideshow-item-img',
        
        '.gallery-strips-item-wrapper'
        
        ]
        
        .join ( ', ' );
        
      const $elements = $( selector, this );
      
      let $images = $( 'img', $elements );
      
      $elements.each ( callback );
      
      }
      
    $galleries.each ( callback );
    
    } );
    
  </script>

```

 ![image](https://us1.discourse-cdn.com/flex020/uploads/elfsight/original/3X/e/5/e56ed38d15486697aef96530afec1357670a175a.jpeg)

---

<div class="post-metadata">

**Author:** ![Bec\_Brittain](https://sea2.discourse-cdn.com/flex020/user_avatar/community.elfsight.com/bec_brittain/32/34812_2.png) [@Bec\_Brittain](https://community.elfsight.com/u/Bec_Brittain)\
**Post date:** [August 22, 2024, 3:03pm UTC](https://community.elfsight.com/t/how-to-make-a-slideshow-randomize/65371/2 "2024-08-22T15:03:52Z")

</div>

This is great, I’ve been trying other solutions to no avail. This solution looks like you can’t use captions, however, because you’re using the description field for the “two-gsior” tag. Any way around that?

---

<div class="post-metadata">

**Author:** ![tuanphan](https://sea2.discourse-cdn.com/flex020/user_avatar/community.elfsight.com/tuanphan/32/3165_2.png) [@tuanphan](https://community.elfsight.com/u/tuanphan)\
**Post date:** [August 22, 2024, 11:22pm UTC](https://community.elfsight.com/t/how-to-make-a-slideshow-randomize/65371/4 "2024-08-22T23:22:16Z")

</div>

I just created another example but with Gallery Block Slideshow + Caption, you can check it here  
[https://phuongvit.squarespace.com/slideshow-random?noredirect](https://phuongvit.squarespace.com/slideshow-random?noredirect)  
pass: abc

Here you can add Caption over image.

This requires some customization on the site so if you want to apply it you can add me as a contributor, I will add the code and guide you to add it to the slideshow

---

<div class="post-metadata">

**Author:** ![Bec\_Brittain](https://sea2.discourse-cdn.com/flex020/user_avatar/community.elfsight.com/bec_brittain/32/34812_2.png) [@Bec\_Brittain](https://community.elfsight.com/u/Bec_Brittain)\
**Post date:** [August 23, 2024, 1:03pm UTC](https://community.elfsight.com/t/how-to-make-a-slideshow-randomize/65371/5 "2024-08-23T13:03:47Z")

</div>

![Screenshot 2024-08-23 at 9.00.51 AM](https://us1.discourse-cdn.com/flex020/uploads/elfsight/original/3X/5/e/5eaec20cab848f44188545ce33e25e4f0a26a05b.jpeg)

Thanks for the offer of help. This is the current format of my slideshow which I’d like to keep – assuming I can just move the captions in your example with some css?

Also, I tried the plugin for randomizing galleries and it didn’t work (SQSP themes or something), and I’m thinking it’s because my gallery slideshow is a section, not a block. Will that be an issue with your method?

---

<div class="post-metadata">

**Author:** ![tuanphan](https://sea2.discourse-cdn.com/flex020/user_avatar/community.elfsight.com/tuanphan/32/3165_2.png) [@tuanphan](https://community.elfsight.com/u/tuanphan)\
**Post date:** [August 23, 2024, 3:31pm UTC](https://community.elfsight.com/t/how-to-make-a-slideshow-randomize/65371/6 "2024-08-23T15:31:03Z")

</div>

I also use SQSPTHEMES, it works with Gallery Block only. You can consider using Gallery Block Slideshow

---

<div class="post-metadata">

**Author:** ![user2754](https://avatars.discourse-cdn.com/v4/letter/u/7993a0/32.png) [@user2754](https://community.elfsight.com/u/user2754)\
**Post date:** [March 19, 2025, 6:22pm UTC](https://community.elfsight.com/t/how-to-make-a-slideshow-randomize/65371/7 "2025-03-19T18:22:08Z")

</div>

Hello, can I use this code for a simple grid gallery ?  
Thank you

---

<div class="post-metadata">

**Author:** ![tuanphan](https://sea2.discourse-cdn.com/flex020/user_avatar/community.elfsight.com/tuanphan/32/3165_2.png) [@tuanphan](https://community.elfsight.com/u/tuanphan)\
**Post date:** [March 20, 2025, 12:04am UTC](https://community.elfsight.com/t/how-to-make-a-slideshow-randomize/65371/8 "2025-03-20T00:04:07Z")

</div>

With Gallery Section Grid, use this code

```auto
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.0/jquery.min.js"></script>
<script>
document.addEventListener('DOMContentLoaded', function() {
    const productGrid = document.querySelector('body');
    if (productGrid) {
        var productItems = productGrid.querySelectorAll('.gallery-grid-item');
        for (var i = productItems.length; i >= 0; i--) {
            productGrid.appendChild(productItems[Math.random() * i | 0]);
        }
    }
});
</script>

```

If you need to do this for specific gallery, just change  
body  
to gallery grid id  
or share link to page, I can check & give you exact id/code

---

<div class="post-metadata">

**Author:** ![user2754](https://avatars.discourse-cdn.com/v4/letter/u/7993a0/32.png) [@user2754](https://community.elfsight.com/u/user2754)\
**Post date:** [March 20, 2025, 11:06am UTC](https://community.elfsight.com/t/how-to-make-a-slideshow-randomize/65371/9 "2025-03-20T11:06:24Z")

</div>

Thank you for your answer. I can’t seem to make it work though ☹  
I’m still on a trial version. But here are the two id section number I see for this section

#collection-67b5f9cb88299161acd3e9ca

section[data-section-id=“67dbf47a7a67a8523d8287e3”]

Not sure how to integrate it in the code you gave me either.

I just want this specific shuffle effect on this page. To do so i can imagine that i have to integrate the code in the advanced section of this specific page?

 ![Screenshot 2025-03-20 at 12.01.06](https://us1.discourse-cdn.com/flex020/uploads/elfsight/original/3X/2/8/284bb12471f9a64d0a5d550130caa647d021aabf.jpeg)

---

<div class="post-metadata">

**Author:** ![tuanphan](https://sea2.discourse-cdn.com/flex020/user_avatar/community.elfsight.com/tuanphan/32/3165_2.png) [@tuanphan](https://community.elfsight.com/u/tuanphan)\
**Post date:** [March 20, 2025, 11:43am UTC](https://community.elfsight.com/t/how-to-make-a-slideshow-randomize/65371/10 "2025-03-20T11:43:17Z")

</div>

Do you have link to Pub page?  
and you need to add code to Code Injection \> Footer to make code load properly

---

<div class="post-metadata">

**Author:** ![user2754](https://avatars.discourse-cdn.com/v4/letter/u/7993a0/32.png) [@user2754](https://community.elfsight.com/u/user2754)\
**Post date:** [March 20, 2025, 11:49am UTC](https://community.elfsight.com/t/how-to-make-a-slideshow-randomize/65371/11 "2025-03-20T11:49:23Z")

</div>

can you use this link? its a trial version

> **[Squarespace — Login](https://login.squarespace.com/api/1/login/oauth/provider/authorize?client_id=wAHMs0yNCd2CyyoI0Eclva4GmZ1qqRPx&redirect_uri=https%3A%2F%2Frectangle-terrier-bl9t.squarespace.com%2Foauth-connect&state=v1.local.QouTzE4MjKshxWMvzF-7ITS1uZiSFltc7DUer4nIyhuiYRSnIk8HUaJiwj792WFYtKjeQ9YD5k74fu3sIY2ZYBGwQlYK65QWLlt7pdiufW4-JI4b76ivMFZIV-CizJBuFa6gQlpjPNAmd3mBzSL3rZk9EDb5C-eHHLqNophOvN0PJT1qx6OZy4-ql5BCne9PLH9d1643fABRGAtgtx0af3t91UbBqaI0XbU3qs5MEhD6i0uUGpbR8kf7ZTLcQSq7XZIjkwxVpdLx4ZcfRIcGYZq-eKIidmSQs4TiK6xg9rqAAH-CjsJpDPfV3U3KCtRMICqEOPcFWa6CnGvW4FYqPgml18M4VKdcWB0EYDzhYVzOy-szJxd4kAAo0UlGvaXqzNUap6uEy9rFtYvTF114YZNDvWqPBv4&overrideLocale=fr-FR&options=%7B%22isCloseVisible%22%3Atrue%2C%22isCreateAccountViewActive%22%3Afalse%7D)**
>
> Log into your Squarespace account. Squarespace is the all-in-one solution for anyone looking to create a beautiful website.

---

<div class="post-metadata">

**Author:** ![tuanphan](https://sea2.discourse-cdn.com/flex020/user_avatar/community.elfsight.com/tuanphan/32/3165_2.png) [@tuanphan](https://community.elfsight.com/u/tuanphan)\
**Post date:** [March 20, 2025, 12:03pm UTC](https://community.elfsight.com/t/how-to-make-a-slideshow-randomize/65371/12 "2025-03-20T12:03:47Z")

</div>

What is pass?

 ![image](https://us1.discourse-cdn.com/flex020/uploads/elfsight/original/3X/f/d/fd99f6c312972542edb4e501fad6d0b7f961ec60.png)

---

<div class="post-metadata">

**Author:** ![user2754](https://avatars.discourse-cdn.com/v4/letter/u/7993a0/32.png) [@user2754](https://community.elfsight.com/u/user2754)\
**Post date:** [March 20, 2025, 1:50pm UTC](https://community.elfsight.com/t/how-to-make-a-slideshow-randomize/65371/13 "2025-03-20T13:50:53Z")

</div>

Hello Tuan Phan, can I send you the password by mail?

---

<div class="post-metadata">

**Author:** ![tuanphan](https://sea2.discourse-cdn.com/flex020/user_avatar/community.elfsight.com/tuanphan/32/3165_2.png) [@tuanphan](https://community.elfsight.com/u/tuanphan)\
**Post date:** [March 20, 2025, 3:11pm UTC](https://community.elfsight.com/t/how-to-make-a-slideshow-randomize/65371/14 "2025-03-20T15:11:01Z")

</div>

You can use this code, if it doesn’t work, send password to [my email](mailto:info@beaverhero.com)

```auto
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.0/jquery.min.js"></script>
<script>
document.addEventListener('DOMContentLoaded', function() {
    const productGrid = document.querySelector('#collection-67b5f9cb88299161acd3e9ca .gallery-grid-wrapper');
    if (productGrid) {
        var productItems = productGrid.querySelectorAll('.gallery-grid-item');
        for (var i = productItems.length; i >= 0; i--) {
            productGrid.appendChild(productItems[Math.random() * i | 0]);
        }
    }
});
</script>

```

---

<div class="post-metadata">

**Author:** ![user2754](https://avatars.discourse-cdn.com/v4/letter/u/7993a0/32.png) [@user2754](https://community.elfsight.com/u/user2754)\
**Post date:** [March 20, 2025, 10:21pm UTC](https://community.elfsight.com/t/how-to-make-a-slideshow-randomize/65371/15 "2025-03-20T22:21:09Z")

</div>

Ohhhhh thats fantastic. It works!!!  
I’m so happy. It’s exactly what I wanted to achieve.  
So grateful
