Trusted WordPress tutorials, when you need them most.
Beginner’s Guide to WordPress
WPB Cup
25 Million+
Websites using our plugins
16+
Years of WordPress experience
3000+
WordPress tutorials
by experts

How to Redirect Users to a Random Post in WordPress

Editorial Note: We earn a commission from partner links on WPBeginner. Commissions do not affect our editors' opinions or evaluations. Learn more about Editorial Process.

Do you want to redirect users to a random post in WordPress?

By showing a random blog post, you can encourage visitors to read more of your articles. This can keep them on your website for longer and get you more pageviews.

In this article, we will show you how to easily redirect users to a random post in WordPress.

How to redirect users to a random post in WordPress

When to Redirect Users to a Random Post

Redirecting users to a random post can be useful when you have a bunch of blog posts, but only a few of them get a lot of views.

By sending visitors to a random post, they can discover new articles they may not have visited. This can increase pageviews and reduce the bounce rate in WordPress.

You might also want to add a ‘Random post’ button to your 404 error pages. This way, they may be less likely to exit your website and become interested in exploring your content further.

That being said, let’s take a look at how to redirect users to a random post in WordPress.

Video Tutorial

Subscribe to WPBeginner

If you don’t want to watch the video, then you can continue reading the text version below.

Redirecting Users to a Random Post in WordPress

The easiest way to redirect users to a random blog post is by using Redirect URL to Post. This plugin creates a redirect URL that you can add to any location that supports links, such as a button, email newsletter, or navigation menu.

The first thing you need to do is to install and activate the Redirect URL to Post plugin. For more details, see our step-by-step guide on how to install a WordPress plugin.

Upon activation, you will see some information about the different URL query parameters you can use to redirect visitors to a random page.

Redirect URL parameters

To redirect users to a random WordPress post, simply copy the URL and then add it to any location you want, such as a navigation menu, a sidebar widget, or a call-to-action button.

If you have moved away from this page or closed it by accident, then here are the different queries that redirect to a random post. You will need to replace http://www.example.com with your own domain name:

  • http://www.example.com/?redirect_to=random&pk_campaign=random. Redirects to a random post and tracks the visit. This is a great option if you want to track website visitors to your WordPress site.
  • http://www.example.com/?redirect_to=random&each_once=rewind. Redirects to a random post, avoiding duplicates, and then starts over again.
  • http://www.example.com/?redirect_to=random&count=10. Redirects to a random post among the 10 latest posts.
  • http://www.example.com/?redirect_to=random&after=1%20month%20ago. Redirects to a random post among the posts that are not older than 1 month.

Pro Tip: This is optional, but the plugin developer suggests adding &cache=120 parameter at the end of your URL. This helps store your random results for 120 seconds, which will make your WordPress site load faster for users.

You can also add a ‘Random post’ button to any page, post, or widget-ready area using the following shortcode:

[redirect_to_post_button]

For more information on how to place the shortcode, please see our guide on how to add a shortcode in WordPress.

When readers click on the random redirect button, they will be sent to a random blog post on your WordPress website.

How to redirect visitors to a random post in WordPress

If you are using a block-based WordPress theme, then you can also add this button to any template or pattern in the Full Site Editor.

To get started, head over to Appearance » Editor in the WordPress dashboard.

Opening the full site editor (FSE)

You will now see some menu items to edit your website using the Full Site Editor.

For demonstration, go ahead and select ‘Templates.’

Selecting the Templates menu in WordPress Full Site Editor

You can now click on the template or template part you want to edit, like the homepage or an archive page.

As an example, we will add the ‘Random Post’ button to the 404 page template, but the steps will be exactly the same no matter which template you select.

Adding shortcode to a 404 template

WordPress will now show a preview of the template or template part.

To add the random post shortcode, go ahead and click on the small pencil icon.

Adding a random post CTA to a 404 page template

With that done, click on the blue ‘+’ icon in the top left corner.

In the search bar, you need to type in ‘Shortcode.’

Adding shortcode to a WordPress template or template part

When the right block appears, drag and drop it onto the theme template.

You can now either paste or type the [redirect_to_post_button] shortcode into this block.

How to redirect readers to a random post in WordPress

After that, go ahead and click on the ‘Save’ button.

Now, simply visit your WordPress blog to see the random post button in action.

How to redirect to a random post from a 404 page

We hope this article helped you learn how to redirect users to a random post in WordPress. You may also want to see our guide on how to increase your blog traffic or our expert picks for the best WordPress SEO plugins and tools that you should use.

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

Disclosure: Our content is reader-supported. This means if you click on some of our links, then we may earn a commission. See how WPBeginner is funded, why it matters, and how you can support us. Here's our editorial process.

Editorial Staff

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi with over 16 years of experience in WordPress, Web Hosting, eCommerce, SEO, and Marketing. Started in 2009, WPBeginner is now the largest free WordPress resource site in the industry and is often referred to as the Wikipedia for WordPress.

The Ultimate WordPress Toolkit

Get FREE access to our toolkit - a collection of WordPress related products and resources that every professional should have!

Reader Interactions

10 CommentsLeave a Reply

  1. Syed Balkhi says

    Hey WPBeginner readers,
    Did you know you can win exciting prizes by commenting on WPBeginner?
    Every month, our top blog commenters will win HUGE rewards, including premium WordPress plugin licenses and cash prizes.
    You can get more details about the contest from here.
    Start sharing your thoughts below to stand a chance to win!

  2. Wesley Huang says

    Is that possible to randomly redirect to part of the post? I am thinking of something that allows user to post something under a type, and other user will randomly see one of the post belongs to that category, but not randomly from all the posts

    • WPBeginner Support says

      If you mean you are going to add user-submitted posts then the plugin does have the option to limit the random post selected to those within the specific category or other parameters.

      Admin

    • WPBeginner Support says

      It would require coding knowledge and would not be beginner friendly if you tried to do it manually.

      Admin

  3. Elena says

    Hi,

    I have a website created in WordPress.com. I wanted to have a self hosted site so i moved it to Site Ground. I also wanted to have my site in WordPress.org so I could have more freedom to change my site. Can you help me how I can move my site to WordPress.org? Thanks.

Leave A Reply

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WPBeginner Assistant
How can I help you?

By chatting, you consent to this chat being stored according to our privacy policy and your email will be added to receive weekly WordPress tutorials from WPBeginner.