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