Freelance WordPress Developer
NS COPYRIGHT 2019. ALL RIGHTS RESERVED.

Work

How to remove post categories from the homepage

Created: 05 Sep 2015  / Categories: Themes

How To Hide or Remove Categories from a WordPress Homepage

When displaying your latest posts on the homepage, you might want to exclude some categories from displaying on this page.

There are many reasons why you would want to do this. You might want to keep your homepage for only news posts and relegate the rest of the posts to other sections accessed through the menu.

In any case, what we will need to modify is the WordPress loop. All WordPress themes make use of the loop, and the best way to modify it is by using the pre_get_posts hook.

Removing categories from the homepage can sometimes turn out to be quite a frustrating act for beginners, so here’s the easy way to do it.

In your theme’s functions.php file, just insert the following code, replacing the category IDs with the ones you want to exclude:

Read more about pre_get_posts here.

Thank you for seeing my code snippet and fell free to share and comment :) .Do you have any interesting changes to your "your latest posts on the homepage" that you make or some other cool code snippet that you’d like to share? Let everyone know in the comments what cool tricks you’ve come up with or you can let me know by contact me (here)


Email Post Contributors When Their Posts Are Published

Created: 17 Aug 2015  / Categories: Email

This WordPress code snippet below will email the Post Author a “post published successful” confirmation for every post published. The code can be also used for the WordPress admin to ...

Top
  • LET'S TALK!

    Fill in the form below to make an enquiry or find my contact details on my contact page.

  • This form collects your name and email address so that I can respond to the enquiry(ies) that you submit via this website. Please check my privacy policy for the full story on how I use, protect and manage your submitted data.