WordPress : Redirecting to a random page

To create a random redirect in WordPress, you need to query your posts and get a random post ID and then use wp_redirect() function in WordPress to redirect users away to that page.

 

Additionally if the redirect is a 301, you can add a status to the wp_redirect() function in the following way.

 

The default value if left empty is 302.

Leave a Comment

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>