Display Random Posts in WordPress

Tutorial Difficulty Level    

This method requires you to add code to your WordPress theme files, so exercise caution.

First thing you need to do is add this code in your theme’s functions.php

This code simply creates a function that displays 5 random posts. It then creates a shortcode so that you can easily display random posts anywhere on your site. Lastly, it enables shortcodes to be executed inside WordPress widgets so that you can use shortcode inside a text widget.

Now you can easily display random posts inside a WordPress post, page, or text widget using the shortcode [wpb-random-posts].