Three ways /random/ can hurt a site
WordPress 7.2 turns on a /random/ address for every site on December 8. It adds load that a cache cannot absorb, it can surface content you never linked to, and one filter turns it off.
By Tom Morton, Six Foot 3
WordPress 7.2 ships on December 8. From that day, a visit to /random/ on your site redirects to a random published post, and each archive gets its own random address. It is on until you turn it off. Most of the hundred-plus comments on the dev note want it off by default, and three of their reasons matter for any site.
- Load. A page cache cannot store a random answer, so every /random/ request runs WordPress and the database. Ryan McCue called that an easy way to take down a small site, because a bot can request the address in a loop. The first version also sorted every eligible post on each request. Rene Hermenau measured 1.88 seconds for one request on a test site with 2 million posts, and 20 requests at once took 14 seconds. Core replaced that query on November 17, and the commit says the cost no longer depends on the number of posts. The request still cannot be cached.
- Exposure. Posts are eligible, and so is any custom post type that is public and has an archive, unless its developer sets the new
randomableargument to false. Many sites keep content out of view only because nothing links to it. Joost de Valk's examples were invoices, offers and pages made for one client. Core has no noindex setting that the feature could respect. - New code on every site. The feature entered core on October 16, and commenters found two bugs in it after the dev note. In one, a page cache could store a single post as the /random/ page. In the other, a site locked to logged-in users still redirected logged-out visitors to post URLs. Both are fixed in the release candidate.
To turn it off, add add_filter( 'wp_enable_random_content_redirect', '__return_false' ); to a must-use plugin. Then save the Permalinks screen to flush the rewrite rules. Jono Alderson's No Random Posts plugin does the same job without code.
To keep it on, list the post types on the site that are public and have an archive. Set randomable to false on each type that visitors should not land on.
Tom Morton
Tom runs Six Foot 3, his web consulting practice in Miami, Florida. He has been building for the web since 2008, including two years consulting for the company behind WordPress.com.
More from TomGet the WordPress Intelligence Briefing
One email a week: the week's WordPress links and a take like this one.
