Support Portal

24/7 Live Technical Support & Documentation.

24/7 TechSupport

How to Display Random Posts on WordPress Front Page

By default, the latest posts list on the front page gets displayed in reverse chronological order and that is what latest posts is. Can you customize it further?

Can you display random posts on the front page?

Add this small bit of code to your child theme’s functions.php and you can indeed 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
}

comments

Copyright © 2012-2017 Cyber Developer BD . All Rights Reserved.