below code play video in page using shortcode : [single_video]
how to make it play shuffle all the videos at that folder in a loop using short code that can pass folder name like : [shuffle_play_gallery folder="naturevideos"]
function display_single_video() {
$video_url = 'https://website.com/videos/test.mp4';
// Generate the video element
$video_element = '<video width="320" height="240" controls>
<source src="' . $video_url . '" type="video/mp4">
Your browser does not support the video tag.
</video>';
return $video_element;
}
// Register the shortcode to display the single video
add_shortcode('single_video', 'display_single_video');
any help appreciated and
thanks for help
2
Answers
The client (web browser) will need to know a list of available files. You can either:
Afterwards, it’s a client-side task. I would do it like this:
ended
event (documentation)src
attribute on your<video>
element with the next URL.play()
on the elementTo achieve the functionality of playing all videos in a folder in shuffle mode using a shortcode, you can make use of PHP’s glob function to get a list of all video files in the specified folder. Additionally, you can use JavaScript to handle the shuffle and loop functionality.
Here’s an example of how you can modify your code:
This code defines a new shortcode [shuffle_play_gallery] that takes a folder attribute. It retrieves all video files in the specified folder, shuffles them, and generates video elements for each file. The JavaScript part handles the shuffle and loop functionality by hiding and playing videos based on events. Please replace ‘wp-content/uploads/’ with the actual path to your video folder.