Adding autoplay functionality to a video element in Flatsome can significantly enhance the user experience of your website. In this tutorial, we’ll walk you through the process step by step, making it easy for WordPress users of all levels, including beginners.
Whether you’re a seasoned web developer or someone who’s just starting to explore the world of WordPress, by the end of this article, you’ll know how to effortlessly incorporate autoplay into a Flatsome video element.
Understanding Flatsome and UX Builder
Flatsome is a popular WordPress theme known for its flexibility and user-friendly interface. One of its standout features is the UX Builder, which simplifies the process of creating and designing web content. Before we dive into adding autoplay, let’s briefly understand how Flatsome and UX Builder work together.
Adding a Video Element in Flatsome with UX Builder
Accessing the UX Builder Interface in Flatsome
To get started, log in to your WordPress dashboard and navigate to the page or post where you want to add the video element. Click on “Edit” to open the WordPress editor. Within the editor, you’ll find the UX Builder button.
Creating or Editing a Page/Post
If you’re creating a new page or post, select the “+ New” option and choose “Page” or “Post.” Give your page or post a title and click the “Edit with UX Builder” button.
Inserting a Video Element in UX Builder
Inside UX Builder, you can easily add a video element by selecting it from the available elements. Drag and drop the video element onto your page where you’d like it to appear.

Configuring Video Settings and Options in UX Builder
Once the video element is in place, you can configure its settings. Upload your video file or provide a link to the video source. You can also customize the video’s appearance and layout according to your preferences.
Introduction to JavaScript for Autoplay
Now, let’s talk about why we need JavaScript to enable autoplay for the video element. JavaScript is a versatile programming language used in web development to add interactivity and functionality to websites. In our case, JavaScript will help us achieve the autoplay feature seamlessly.
Writing the JavaScript Code for Autoplay
Opening the HTML Element Containing the Video
To enable autoplay, we’ll need to access the HTML element that contains the video. In UX Builder, each element is assigned a unique identifier. You can find your identifier through the Chrome Dev Tools.

Writing the JavaScript Code for Autoplay
Here’s the JavaScript code you’ll need to add to your Flatsome theme. To add it you need to go to Flatsome>Advanced>Global Settings and add it before to “BODY SCRIPTS – BOTTOM” section:
// Wait for the DOM (document) to be fully loaded before executing the code
document.addEventListener('DOMContentLoaded', () => {
// Set a timeout to delay the execution of the code by 150 milliseconds
setTimeout(() => {
// Find the video element with the ID 'video-7125-1' and store it in the 'video' variable
const video = document.querySelector('#video-7125-1');
// Mute the video to ensure it doesn't play with sound
video.muted = true;
// Start playing the video
video.play();
}, 150); // The code inside this setTimeout will run after a 150-millisecond delay
});
Replace ‘your-video-element-id’ with the actual ID of your video element.
Explanation of the Autoplay Code
This JavaScript code waits for the page to load fully, identifies the video element by its ID, sets the autoplay attribute to true, and then loads the video. It also set the audio of the video to “mute” to avoid Google Chrome preventing the autoplay.
Where to Insert the JavaScript Code in Flatsome/UX Builder
You should insert the JavaScript code in the “Custom JS” section of your Flatsome theme. Go to “Flatsome>Advanced>Global Settings” and paste the code there.
Testing and Troubleshooting
Previewing the Page to Test Autoplay Functionality
After adding the JavaScript code, save your changes and preview the page. The video should now autoplay when the page loads. If it doesn’t work as expected, let’s move on to troubleshooting.
Common Issues and Troubleshooting Tips
Common issues may include typos in the JavaScript code or conflicts with other plugins or themes. Double-check the code and ensure it’s correctly placed in the “Flatsome>Advanced>Global Settings” section. You must check you also added a timeout of at least 150ms in your JavaScript script as in my example above to make it work properly with any browser.
Making Adjustments and Retesting
If autoplay still doesn’t work, try adjusting the JavaScript code or deactivating conflicting plugins. Test your changes and keep refining until autoplay functions smoothly.
Conclusion
In conclusion, adding autoplay to a Flatsome video element is a straightforward process that enhances the user experience on your WordPress site.
By following this tutorial, you’ve learned how to use UX Builder to add a video element and how to employ JavaScript to enable autoplay. This user-friendly guide ensures that both beginners and experienced WordPress users can implement this feature effortlessly.
Remember, enhancing your WordPress website’s functionality and interactivity doesn’t always require a developer’s assistance. Empower yourself with the knowledge and tools to make your website stand out.