Show random posts on front page WordPress Site

Show random posts on front page

By default, theme option you see “theme supports a static front page” and you see  in Front page displays 2 option

1-Your latest posts

2-A static page


and latest posts list on the front page gets displayed your post posted by lastest, and new post will be displayed first

How to show random posts in wordpress front page

If you want to display, you posts should be displayed random,

Add this code to your child theme’s functions.php and you can  display random posts on your front page.

function alter_query($query){
    if ($query->is_main_query() &&  is_home())
        $query->set(‘orderby’, ‘rand’); //Set the order to random

Normally this function work in all theme. try it

Leave a Reply

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

8 + 2 =

All Rights Reserved 2019 | DesignzRush (OPC) Pvt. Ltd.