How to Redirect Your WordPress Blog Readers to a Random Post

by Vincy. Last modified on July 13th, 2022.

The ‘redirect to random post’ option will be useful for the WordPress or other bloggers, online tutorials website, or any other article directory.  This option is to randomize the selection of one among the vast collection of articles from the article directory which will be quiet interesting.

Being a surprise factor, the ‘redirect to random post’ navigation increases user’s curiosity to visit the random page.

It also provides a scope of adding page navigation with the inter-website linking. The interlinking is the best way of engaging users with your website for a long time. It will increase the pages per session and thereby boost the page views in analytics. It will also help the blogger for gaining new page visits.

In the WordPress blog or any websites being like an article directory, mostly, the pagination will help to browse older content published long back. But, it will too many attempts to go to the very old content. The random redirect might have the link of the older days tutorials randomly regardless of the published date.


The possible ways of getting the random post link are discussed here in this article. There are various plugins available for WordPress to get the random post link. Also, we will see how to present the redirect to random post UI in the WordPress theme.

How to Add Random Post Redirect Option?

We have seen enough convincible reasons for why the random post redirect is needed and how it creates considerable effects on various ranking metrics and helps to boost readership. The next step is about how it should be plotted on our WordPress website in a presentable way.

We simply can add the text links or button navigation in the sidebar or anywhere. But, it will not always get the readers attention by having the simple text links. We can create a banner for showing the random redirect option with a short text and the redirect (image or button) link. The text should tell about how it will be useful to the readers by redirecting.

We can also create the WordPress widget for adding the random post redirect option. Then, it could be inserted to the content by creating shortcodes or by manually changing the theme template markup. The below screenshot shows an example widget UI with a short text and a redirect image button.

Where to Add Random Post Redirect Control in WordPress Website?

After creating the widget, banner or any other form of UI elements, we have to choose the right position to locate the ‘redirect to random post’ control. It basically depends on the purpose of what you are adding the random post control in your WordPress blog.

For example, if you want to engage your reader for a long time on your website, then you have to add this control without interrupting the article flow. Because, most probably, the readers don’t want to jump to a random page while reading an article. So, we should not insert this independent element in between article content.

Instead, we can add this random suggestion next to the related posts of the article. We have seen in a previous tutorial on how to display related posts in WordPress by using Google Matched Content or YARPP plugin.

If you want the user to visit more pages of your WordPress blog, then you can add the ‘redirect to random post’ widget in the right sidebar. The sidebar is one of the best locations to display recommended links, the post of the day question of the day and similarly to display random post recommendation.

Get Random Post link to Redirect the Readers

Here, we are going to see two ways of getting the random post URL to redirect the readers.

  1. By using Redirect URL to Post plugin
  2. By using custom code to query on WordPress post

Using Redirect URL to Post plugin

The Redirect URL to Post plugin is used to get the random post URL by adding the parameter redirect_to=random in the query string.  If you want to learn how to install a WordPress plugin, refer that we have already discussed while creating plugin for showing post taxonomy breadcrumbs.

By installing this plugin the http://yourblogdomain?redirect_to=random link will redirect the user to a random post’s view page. This plugin also gives a shortcode [redirect_to_post_button] for displaying random post redirect button.

Using WordPress Custom Code

I always prefer using WordPress code instead of using any third-party plugins. In this section, a code snippet is added for querying the WordPress database for getting the random post URL.

 * Template Name: Redirect to Random Post Template
    'showposts' => 1,
    'orderby' => 'rand'

if (have_posts()) :
    while (have_posts()) :

        $random_post_url = get_the_permalink();

<!-- Add your Redirect to Random Post UI markup -->


This code is added in a custom page template that can be inserted wherever we want to add it into the theme files, custom templates by using WordPress get_template_part() function.

Written by Vincy, a web developer with 15+ years of experience and a Masters degree in Computer Science. She specializes in building modern, lightweight websites using PHP, JavaScript, React, and related technologies. Phppot helps you in mastering web development through over a decade of publishing quality tutorials.

Leave a Reply

Your email address will not be published. Required fields are marked *

↑ Back to Top

Share this page