Connect with us

WP Stuff

WordPress Code: Random Post Redirect Button

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:

20+ WordPress Plugins for membership sites

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).

 

Continue Reading
You may want to check out:
*some of our articles and lists include affiliate links to fund our operations (e.g. Amazon, Elegant Themes, Envato). Please read our disclaimer on how we fund Exxponent.
You may also like...
Click to comment

Leave a Reply

Your email address will not be published. Required fields are marked *

More in WP Stuff

To Top