I am a fan of the Divi theme from Elegant Themes. It’s got a lot of features built in so you don’t need to buy as many plugins to give your site the visual oomph you want.

One thing it doesn’t have though is the built-in ability to randomize sliders. I asked their support department if they knew how to do this and they just responded that it’s not built in. Well duh, I knew that. They also couldn’t point me in a direction for a solution.

I knew there was a solution out there – I’d used it once before but forgotten which site I’d needed it for, so I went looking. There really weren’t many posts on how to randomize a Divi slider. Actually, there was only ONE. This is surprising given how many people use Divi and how many companies make tutorials to cater to Divi users.

Anyway, I found someone who’d created a simple Javascript that does the trick. If you need to randomize your Divi slider, here’s the Javascript:

<script type="text/javascript">
jQuery(document).ready(function(){
  var item = document.querySelector('.et_pb_slider .et_pb_slides');
  if(item!=null){
    for (var i = item.children.length; i >= 0; i--) {
      item.appendChild(item.children[Math.random() * i | 0]);
    }
  }
});
</script>

In case anyone’s wondering, I found this on Stack Overflow (link opens in new window).

I hope this helps someone, someday 🙂