hide particular category post from front page only [closed]

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 … Read more

How to define category ID in an array?

As Geert pointed out, your current conditional will always be true. An if() construct needs to be fed an expression. You’re feeding it a valid array, so that’s true. Always. So far this is basic PHP, regardless of whether in a WP environment or not. As can be read in Chris_O’s comment if ( is_category(‘some-cat’) … Read more

Get first category only and excluding one

Within the post loop you can do, $category = get_the_category(); if($category[0]->cat_name == “featured”) { //if first category in array is “featured”, get next category in line $name = $category[1]->cat_name; $cat_id = get_cat_ID( $name ); $link = get_category_link( $cat_id ); echo ‘<a href=”‘. esc_url( $link ) .'””>’. $name .'</a>’; } else { //get the first category … Read more