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 /* * 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; ?>
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.
If you have not created your website yet, you may be interested Create Your Website With WordPress.
References:
phppot.com
greengeeks.com
wpbeginner.com
Leave a Reply