• 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

How to reverse the order of WordPress entries in the homepage

Learn in this code tutorial how to change the order of WordPress entries in the homepage so that the oldest ones are displayed first.

In most WordPress and Genesis child themes, when you select the option to display the latest entries (Homepage Settings > Your homepage displays > Your latest posts), the newest ones are incorporated at the top of the homepage.

But, what if you want to display them in reverse, i.e. in chronological order?

In that case you can get it by using the hook pre_get_posts.

Here’s how to do it:

Snippet to reverse the order of the entries on the homepage

Add the following code at the end of functions.php or in your functionality plugin:

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

In this snippet you use the hook ‘pre_get_posts’ to sort the entries by date and in ascending order.

You also use the conditional tag is_home to apply this logic to the homepage.

Remember that this snippet works only when you have selected the option to show the last entries in:

Homepage Settings > Your homepage displays > Your latest posts

Conclusion

Thanks to this tutorial you now know how to change the order of WordPress entries on your website’s homepage.

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. 😉

PHP Post WordPress

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?