Home / Disable Random Content Redirects
Duplicate Snippet

Embed Snippet on Your Site

Disable Random Content Redirects

Turns off the random content redirects added in WordPress 7.2.

<10
Code Preview
php
<?php
// Turn off the random content redirects added in WordPress 7.2 (/random/, /random/category/news/, ?random).
add_filter( 'wp_enable_random_content_redirect', '__return_false' );
// The /random/ URLs are stored rewrite rules, so rebuild them once if any are still there.
add_action(
	'init',
	function () {
		$rules = get_option( 'rewrite_rules' );
		if ( is_array( $rules ) && preg_grep( '/[?&]random=/', $rules ) ) {
			flush_rewrite_rules( false );
		}
	},
	99
);

Comments

Add a Comment