WordPress offers many ways how to display posts in random order1. Sometimes, however, you want to show one – and only one – random post.
There are several reasons why you may want to show a random post:
- revive old content
- give an equal chance to all authors
- increase on-site engagement and visitor retention for a better SEO score
All you need is the free plugin Redirect URL to Post from the official WordPress repository. It offers caching of database results (default is 60 seconds) and many other advanced features that I will present below.
After you installed and activated the plugin, you simply add ?redirect_to=random to the end of your site’s URL. For example:
Once you press enter, the plugin will automatically pick a random post and insert the correct URL.
This URL can be used in any menu or button. You can even send it to your newsletter subscribers.
Higher Probability For Recent Posts
The feature I like most is the option to use a different probability for older and newer posts. Recent posts are naturally more interesting and relevant, so you may want to show them more often.
You will need two parameters: count to determine the amount of new posts that receive a different weight and bias to determine the percentage that these posts should appear.
Here is an example:
In this example the first 10 posts are picked with a probability of 80% and the rest with a probability of 20%. You can see in the example that only the first parameter is added with a „?“ while all the others use „&“.
Power users may want to check out the parameter offset that lets them skip the very latest posts.
Use Only a Subset of Posts
Sometimes you don’t want to consider all posts but only a subset. Fortunately, the plugin lets you filter by author, post type (e.g. products), time frame or others.
The following link lets you redirect to a random post that is older than 1 month but not older than 6 months. That way you can revive posts that are neither brand-new nor totally outdated. Relative time formats give you a powerful tool to determine a point in time.
Note that „month“ is used in singular and that spaces are encoded as „%20“. Without spaces the parameters will be more readable.
https://www.my-wordpress-blog.com/?redirect_to=random&before=1 month ago&after=6 month ago
Track Random Redirects With Analytics
If you want to track redirected visitors with Google Analytics, you can add a tracking parameter that will be carried over to the final URL.
Supported tracking parameters are utm_source, utm_campaign, utm_medium, utm_term, utm_content, pk_campaign, pk_kwd, pk_source, pk_medium and pk_content
The plugin Redirect URL to Post comes with a handy set of options to send your visitors to a random post.
You can find more details and other possibilities of redirects in the documentation.
Photo by James Bowe