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.

add_action(‘pre_get_posts’,‘alter_query’);
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 *

2 + 9 =


Tech Contents © 2016
Inline
Inline