You can use the Wonder Gallery plugin to easily create images and videos for your WordPress website. This tutorial will guide you on how to dynamically change the images and videos in the gallery using JavaScript.
An online demo is as follows: Clicking the button will remove the first item from the gallery, add a cat image, and a YouTube video to the playlist.
Dog
Dog
cute dug
Dog
WordPress Gallery
The requested content cannot be found
The HTML code of the button is as follows: In this tutorial, we assign it an ID modify-gallery.
<buttonid="modify-gallery">Click to change the gallery playlist</button>
To enable the function of the button, you can add the following JavaScript to your website script file, or in Wonder Gallery, edit the gallery, go to the step 3 Options tab, Advanced Options, and add the following code to the Custom JavaScript input box:
If you add the code to the plugin, the plugin will automatically substitute the macro variable GALLERYID in the code with the current gallery ID, eliminating the need for manual changes. If you add the code to your own script file, you will need to replace it manually.
The following code snippet removes the current gallery display: