• Skip to primary navigation
  • Skip to main content
OsomCode

OsomCode

Awesome code tutorials for WordPress and Genesis

  • Subscribe
  • My account
    • Edit profile
    • Favorites
    • Update credit card
  • Login

Display blog entries in random order in WordPress

Learn how to display blog posts randomly in a WordPress theme using code.

In most WordPress themes and Genesis child themes the latest posts are displayed on the blog page

In previous tutorials I explained how to reverse the order (from oldest to newest) or how to exclude categories.

But what if you want them to have no particular order? No problem.

You can display the posts in random order easily thanks to the pre_get_posts hook and the WordPress conditional tags.

Let’s see how:

Code to display posts in random order on the blog page

Add the following snippet to the end of the functions.php file:

To see this and another 839 code snippets of this website, login or subscribe here.

Thanks to this block, the blog page entries will be displayed randomly. And each time it is visited it will show different entries.

Conclusion

Now, thanks to the pre_get_posts hook and WordPress conditional tags, you know how to display blog page posts randomly in any WordPress theme.

Any questions? Let me know in the comments.

And if you want to give me any suggestion for future tutorials, leave it in the contact form. Advantages of being a subscriber. 😉

Genesis Framework PHP Post

To leave read and make questions about this code, you can login or register.

  • About OsomCode
  • FAQ
  • Contact

Legal Notice · Privacy Policy · Cookie Policy · Terms and conditions
Copyright © 2023

Lost your password?