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.
Why You Should Redirect Users to a Random Post?
By default, WordPress posts appear in reverse chronological order, so users will see the newest post first. If you regularly post new blogs, then visitors may not get the chance to see your older articles.
One solution is to redirect visitors to a random post using a button or a link. This helps readers discover new blog posts they may not have otherwise visited, which can increase pageviews and reduce the bounce rate in WordPress.
Another option is to add a random post link to your site’s main navigation menu or any other area that supports links.
That being said, let’s take a look at how to redirect users to a random post in WordPress.
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.
To redirect users to a random post, simply copy the URL and then add it to any location you want, such as a navigation menu or sidebar widget.
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.
You can also add a ‘Random post’ button to any page, post, or widget-ready area using the following shortcode:
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 button, they will be redirected to a random blog post on your WordPress website.
If you are using one of the newer block-based themes, then you can also add this button to any template or template part.
To get started, head over to Appearance » Editor in the WordPress dashboard.
By default, the full site editor shows your theme’s home template, but you can add shortcodes to any template or template part, such as the header or footer.
To see all the available options, just select either ‘Templates’ or ‘Template Parts’.
You can now click on the template or template part you want to edit.
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.
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.
With that done, click on the blue ‘+’ icon in the top left corner.
In the search bar, you need to type in ‘Shortcode’.
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.
After that, go ahead and click on the ‘Save’ button.
Now, simply visit your WordPress blog to see the random post button in action.
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.