Skip to content

Did you know?

WordPress 7.2 adds a /random/ URL that redirects visitors to a random post.

Turn it off with the wp_enable_random_content_redirect filter if your page cache could serve one redirect to everyone.

  • Web servers
  • Applies to WordPress 7.2+
  • Last checked

Explained

From WordPress 7.2, every site with pretty permalinks answers /random/ with a 302 redirect to a random published post. It works out of the box: no plugin, no setting to turn on. You can rename the base under Settings > Permalinks > Random base, and custom post types can join in with the new randomable argument of register_post_type().

If you don’t want it, or your full-page cache or CDN might store one redirect and serve it to everyone, turn it off with one line in a must-use plugin such as wp-content/mu-plugins/no-random.php:

<?php
add_filter( 'wp_enable_random_content_redirect', '__return_false' );

We tested this on WordPress 7.2 RC4: before the filter, each request to /random/ returned a 302 to a different post; with the filter, it stopped redirecting. Also check that you don’t already have a page with the slug random.

Learn more

← All tech tips · Suggest a fix

Back to top