This is ideal if you love a channel and just want to enjoy a random video. One of my favorites features a Stellaris-style soundtrack, with regular updates and great quality. I know I’ll enjoy every video, especially since they’re all an hour long.
When I want to get into the moment, I just click a link and continue what I was doing, usually playing it through my Bluetooth speaker or desktop sound system at low volume — https://maggew.com/random-SciFiAmbience
This shouldn’t take you too long, maybe 10 minutes to get up and running for something that can pay serious dividends to future you.
- Download addon to Video Extract URLs — https://chromewebstore.google.com/detail/youtube-url-extractor/jmilibpbdpajjnabchfpfmmmjgbimefo
- Visit favorite YouTube channel and scroll to very bottom of videos page so you can “fetch” all the URLS instead of just the top 10 or 20 that load
- Click Extract URLs than Copy URLs to clipboard
- Visit an online tool to add a prefix and suffix… we want to prepend a quote symbol and append a quote symbol with a comma… I like this one — https://text-tools.dev/prefix-suffix-lines
- After you copy to clipboard, we’ll want to create a new snippet than paste and replace the lines below in the code example
- Log into WordPress website and Add new snippet than copy / paste the text below and activate.
- Visit yourdomain.com/future-SciFiAmbience
- *(optional) change line #4 random_slug to whatever you want
- *(optional) update your blank new tab landing page or create a bookmark for you visit when you wanna vibe out to some jams…
<?php
// Add this snippet to your theme's functions.php or use a plugin like "Code Snippets" to include it.
add_action('init', function() {
$random_slug = 'random-SciFiAmbience'; // The slug to trigger the random video
$request_uri = trim($_SERVER['REQUEST_URI'], '/');
if ($request_uri === $random_slug) {
// Define the list of YouTube video URLs
$youtube_videos = [
"https://www.youtube.com/watch?v=G_-XgbDVUdQ&t=406s",
"https://www.youtube.com/watch?v=_OcDW4p7kHo",
"https://www.youtube.com/watch?v=VTrMU3WS-lY&t=1s",
"https://www.youtube.com/watch?v=kiIW2tSfSrk",
"https://www.youtube.com/watch?v=7sju0dQbkJc",
// Add the rest of your URLs here...
"https://www.youtube.com/watch?v=HRu2HVLP5iA"
];
// Choose a random video from the list
$random_video = $youtube_videos[array_rand($youtube_videos)];
// Redirect to the random video
wp_redirect($random_video);
exit;
}
});
People also search:
- Easily Add Random YouTube Video Links to Your WordPress Site
- Simple PHP Code to Show Random YouTube Videos in WordPress
- Create a Random YouTube Video Redirect in WordPress with This Snippet
double-check and make sure all exported URLS from your favorite channel do not have the “&t=406s” at the end or when you visit a link it’ll not start fro the beginning…