In WordPress 7.2, there’s a new feature called “Random”
Maybe not your content per se, but the ability to discover it is with the introduction of the
Your Content is Going to Get More Random/random/endpoint in WordPress 7.2. A request toexample.com/random/will lead end users to a randomly selected published post. The feature is on by default and is built on the existing rewrite,WP, andWP_QueryAPIs. If you have a legitimate reason to not support this on a site, or you simply hate fun, there is a filter to disable this entire feature.
And as I hate fun, I have disabled it.
Now if you know me, you know that is a load of bull. I love fun. Fun is great. But I fundamentally have two issues with this idea of adding in a /random/ page for everyone.
First, the code behind it looks like it could get pretty slow on larger sites (and because it’s random, you can’t cache it properly).
Second reason, and this is bigger, the use-case for random is really limited and will need to be tightly controlled. And right now, the only way to do this is with code.
Speed
Thanks to Ryan McCue, there’s a new ticket about this, but the reality is that the code does not scale well when you talk about having tens of thousands of posts.
I ran into this kind of problem when I wrote up the “Of the Day” feature for LezWatch.TV. Once a day, the site picks a random character and a random show to be the featured items, and it posts them to the socials. But I have some strict parameters to handle this.
- The show cannot be a ‘do not watch’ show
- The content cannot have been selected for the last 400 days
- The show and character must have a valid image (we have defaults)
- The show must have at least one character (there are 3 who don’t)
- The character must have a known actor
We want to promote the good stuff, and we had a hilarious moment where it decided that one show was the show of the day for a week, and I had to have some words.
But in order to meet those parameters, I had to sit down and study the code. I couldn’t just use ORDER BY RAND() because with over 3000 characters and 1500 shows (at the time) I recognized that would get really slow. I do something similar to Ryan, in that we pull ~100 shows/characters that meet the parameters and then pick one from there and cache it for 24 hours.
It runs on a schedule, to select the featured content every morning, and posts around noon ET.
Control
If you didn’t notice, I have those strict parameters. Now let’s talk about how this transfers to more sites. You see, there are no easy, in-WP ways, to limit this kind of thing. There’s no way to say “But not these pages/posts” without writing code.
On this site, HalfElf, I would want to say “Find any random post made in the last 2 years,” because I want to limit it to recent content that is likely to be more valid. To do that, I need code:
add_action(
'pre_get_posts',
static function ( WP_Query $query ) {
if ( wp_is_random_content_query( $query ) ) {
$query->set(
'date_query',
array(
array(
'after' => '2 years ago',
'inclusive' => true,
),
)
);
}
}
);
And that works for content on a blog, but there is a risk in your Custom Post Types. If you have a store, or something crazy like LezWatch, then you run into a risk of weirder content being found randomly. Any public archive’d CPT (like characters, actors, shows, etc) would be random-findable.
Now, on the one hand that’s cool. On the other, if you go to random and get a blog post or a character or a show … which one did you want? Let’s say I only want to show random shows:
add_filter(
'register_post_type_args',
static function ( $args, $post_type ) {
if ( ! in_array( $post_type, array( 'post_type_show' ), true ) ) {
$args['randomable'] = false;
}
return $args;
},
10,
2
);
But for a store? Well do you want someone going to a random blog post from five years ago, a t-shirt that’s out of stock, or a cool new pair of pants?
Now you get to build out a more complicated system that checks:
- Is this a product?
- Is it an in-stock product?
That sounds easy but it’s code, and that means it’s something the site-runner has to know about in advance, build, and test.
And it’s that lack of knowledge that is a massive problem due to unlinked landing pages, invoices, and noindexed pages as they are all published. Core has no way to mark something as “don’t surface this,” which makes this more than a CPT-config problem.
We can say “Oh it’s just a filter” but it’s really only a filter.
Discoverability
Here’s a secret third. How the hell do you find out about the endpoint?
Any upgraded site automatically gets /random/, /random/category/{name}/, and /random/tag/{name}/ enabled fiat.
Unless you have a big ol’ “RANDOM CONTENT” button, how is a visitor going to know about this? We aren’t all Moon Knight.

Jokes aside, though, it’s not something super obvious. I’ve been told that you can put a dice icon on your site for it, but … I wouldn’t click on a random icon like that. Would you?
So now we have a hidden feature that site runners and visitors may not know anything about which means … Bots? That’s who knows about it?
Recommend: Disable (For Now)
Day one (i.e. Now)? Disable this with a plugin or use the filter:
add_filter( 'wp_enable_random_content_redirect', '__return_false' );
Day two? Sit down and go over the site and decide what should and shouldn’t be randomly discoverable. Think about the site’s priorities. What are the parameters for your site and what should be randomly propped up?
Day three? If you’re an agency or build sites for people, you’ve got a big job. Make some kind of control for this for your users. Let them decide “These post types, these ages, these settings.” so they leave you the hell alone.

Leave a Reply