When we have been publishing a post on our website for a long time, we may run into a problem, and that is that users do not read the oldest post.

We have a solution for this, and that is to redirect to random posts, which will also increase the curiosity of our visitors.
Add a WordPress Random Post Link
By default, our WordPress posts appear from the most recent to the oldest, this makes our visitors read the last post first.
This fact makes the posts that are older go unnoticed, and they cost the same work to be created as the last ones.
We have the option of adding a widget to the sidebar with the latest publications, or the most read, or the best rated.
We can also add a search for users to search for what they need on our site.
The random redirect can have the link of the posts of the previous days at random, regardless of the publication date.
Using A Plugin
The first thing we will do is install a plugin to help us, in this case Redirect URL to Post. In the WordPress Dashboard, menu Plugins → Add New. We install and activate the plugin.

Once we have activated the plugin, we can see the URL query parameters for the redirect on the WordPress plugins page. It is as easy as this, it does not require any other configuration.

We may use any of the parameters you offer us to redirect users to random posts, newer posts, and other older articles.
Now we can use the random redirection of the posts in a very simple way, or using a shortcut or a simple link.

We can also use a shortcut, which will add a button to our post.

Using Code
Many times we have talked about how if we have too many plugins installed, we can slow down our website.
In this case, for more advanced users, we can use the following code.
[php] <?php/*
* Template Name: Redirect to Random Post Template
*/
query_posts(array(
‘showposts’ => 1,
‘orderby’ => ‘rand’
));
if (have_posts()) :
while (have_posts()) :
the_post();
$random_post_url = get_the_permalink();
?>
<!– Add your Redirect to Random Post UI markup –>
<?php
endwhile;
endif;
?>
[/php]
This code is added in a custom page template that can be inserted wherever we want to add it to the theme files, custom templates using the WordPress get_template_part () function.
Where to Use the Random Post Link
- A button such as “Read a random post” in your sidebar, footer or end of every post.
- Your 404 page: instead of a dead end, offer visitors a random article to read.
- A “Start here” page, next to your most important guides.
- A newsletter or social media post that sends people to something they may not have seen.
Plugin or Code?
For most sites the plugin is enough: it needs no configuration and lets you choose between a random post, the latest, the oldest, or the previous and next ones. The code option is only worth it if you are comfortable editing your theme, since it must be added to a custom page template. Note that query_posts(), used in the example, is no longer recommended by the WordPress documentation; a developer would normally use WP_Query or get_posts() instead.
Before You Install the Plugin
The Redirect URL to Post plugin has not had a recent update and its page shows it as tested only up to an older WordPress version. Make a backup, check its “Last updated” and “Tested with” details on WordPress.org, and try it first on a page that is not public.
Tips
- A random link is a good extra, but it does not replace good internal linking. Also link your older posts from newer related ones.
- Do not add the random URL to your sitemap. It is a redirect, not a page you want indexed.
- Combine it with widgets for popular or related posts, so visitors have more than one way to discover your content.
If you have not created your website yet, you may be interested Create Your Website With WordPress.
References:
phppot.com
greengeeks.com
wpbeginner.com
Once your site is up and running, give it a polished look with one of our WordPress themes for creatives. You may also like: How To Choose The Best WordPress Plugin.

Leave a Reply