i have setup a new wordpress blog and have few categories one is called news and it updates too frequently and less important so I want news category posts to be excluded from my home page only and if user clicks on that particular category then it can be visible just need to hide news category posts from home.

I prefer if someone can suggest me any plugin which can do same job for me

thanks :)

  • Hide from where? Sidebar? Menu? List of posts? Not all home pages are built equal. Please add some code. – gdaniel Mar 23 '16 at 19:38
  • just from list of posts – Mohit Bumb Mar 23 '16 at 19:38
  • Hard to say exactly without more info or code. You can accomplish what you want by either editing the loop in the theme file (in this case probably index.php or front-page.php or page.php). Or by adding a filter in functions.php that will alter the query. I am sure you can find some plugins too, but if it's a premium theme you might have that option built in already. – gdaniel Mar 23 '16 at 19:43
  • 2
    Plugin recommendations are off-topic here, but the first example for the pre_get_posts action codex page does exactly what you are asking for. – Milo Mar 23 '16 at 19:44
  • perfect that's what I want thanks :) post it as answer so that I can accept :) – Mohit Bumb Mar 23 '16 at 19:48

To exclude a category from the home page, use the pre_get_posts action:

function exclude_category( $query ) {
    if ( $query->is_home() && $query->is_main_query() ) {
        $query->set( 'cat', '-1,-1347' );
add_action( 'pre_get_posts', 'exclude_category' );

In this example, 1 and 1347 are the category IDs you'd like to exclude.

Also see the Conditional Tags page for a list of all the is_ conditionals you can use to target this function to different types of pages.

Not the answer you're looking for? Browse other questions tagged or ask your own question.