Discover in this tutorial how to display the Custom Post Types (CPT) entries on the home of any WordPress child theme using code.
By default, some child themes display the latest blog posts on the home page.
Do you want to display a CPT (or several) entries on the home page as well?
You can do this easily using WordPress hook pre_get_posts
and conditional tags.
Code for displaying CPT entries on the home page
Add the following code at the end of functions.php or in your functionality plugin:
To see this and another 1097 code snippets of this website, login or subscribe here.
Thanks to this snippet, in addition to the posts, the CPT “portfolio” entries will also be displayed on your home page.
You can modify this snippet to your liking, change the name of the CPT, add others, remove articles from the blog… Whatever you need!
This snippet is intended for child themes that have selected the option to display the latest entries in:
Homepage settings > Your homepage displays > Your latest posts.
Conclusion
Now, thanks to WordPress conditional tags, you know how to display CPT entries on the homepage of 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. 😉