WordPress Code: Random Post Redirect Button


Currently trending WordPress plugins

I don’t know about you but I have thousands of posts on my site that are evergreen. Getting my readers to visit them is not always easy. With a random button, you will be able to redirect your readers to a random post to keep them on your site longer. You don’t have to download a plugin to do it either. A simple WordPress function like this takes care of that:

Once you have added this to your functions.php file, you can use the random_post_button shortcode to display it on your website. This script simply queries your database using order=> ‘rand’ to get it done. It is possible to Ajaxify this with a few extra steps (create your js code and enqueue it).

 

More WordPress reading: