(Squarespace) Randomize testimonial carousel

To make testimonial carousel randomize, you can follow these.

#1. First, find Carousel ID.

In my example, it is: section[data-section-id=”67ce38e67ee9543f3f788ef2″]

#2. Next, use this code to Code Injection > Footer.

Remember to update ID.

<script>
document.addEventListener('DOMContentLoaded', function() {
  const slidesContainer = document.querySelector('section[data-section-id="67ce38e67ee9543f3f788ef2"] .user-items-list-banner-slideshow .slides');
  
  if (slidesContainer) {
    const slideItems = Array.from(slidesContainer.querySelectorAll('.slide.list-item'));
    const shuffledItems = [];
    while (slideItems.length > 0) {
      const randomIndex = Math.floor(Math.random() * slideItems.length);
      shuffledItems.push(slideItems.splice(randomIndex, 1)[0]);
    }
    const originalSlides = slidesContainer.querySelectorAll('.slide.list-item');
    originalSlides.forEach(slide => {
      slidesContainer.removeChild(slide);
    });
    shuffledItems.forEach(item => {
      slidesContainer.appendChild(item);
    });
  }
});
</script>

1 Like