Month: January 2013

How to add a random post button in WordPress


I used this method to add a “random post” to this site. I didn’t create a child theme. So it will break when the theme gets updated.

4/24/2016 note:

Here are some details. You need to create a new file inside the theme called page-random.php based on the original page.php.

the added code looks like this and goes right before get_header():


/* Template Name: Random Post */

$randomPost = get_posts(array(
 'numberposts' => 1,
 'orderby' => 'rand'
foreach ($randomPost as $post) {