Title: Excluding a category
Last modified: August 19, 2016

---

# Excluding a category

 *  Resolved [aldodager](https://wordpress.org/support/users/aldodager/)
 * (@aldodager)
 * [16 years, 1 month ago](https://wordpress.org/support/topic/excluding-a-category-1/)
 * hi to everyone
 * im running a digital magazine, and above the post title im adding a line for 
   the reader to know on which category is that post.. right now it looks this way:
 * Featured, Fitness
    POST TITLE
 * I would like to avoid showing FEATURED or MAIN ARTICLE in that line. So far I’m
   using:
 *     ```
       <?php $category = get_the_category();
       echo $category[1]->cat_name;
       ?>
       ```
   
 * But i dont think that this code is what I need. Also, I don’t know how to link
   the Category name to that specific category. So finally I would only like to 
   show:
 * Fitness (linked to fitness category)
    POST TITLE
 * instead of
 * Featured (linked to this cat), Fitness (linked to this cat)
    POST TITLE
 * Probably this has been resolved before but im not good at tweaking wordpress 
   codes
 * Thank you very much!

Viewing 4 replies - 1 through 4 (of 4 total)

 *  [MichaelH](https://wordpress.org/support/users/michaelh/)
 * (@michaelh)
 * [16 years, 1 month ago](https://wordpress.org/support/topic/excluding-a-category-1/#post-1435092)
 * An example of excluding one (or more) categories displaying:
 *     ```
       <?php
       foreach((get_the_category()) as $category) {
           if (!in_array($category->cat_name,array('cat1_to_exclude','cat2_to_exclude','cat3_to_exclude')) ) {
           echo '<a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a> ';
       }
       }
       ?>
       ```
   
 *  Thread Starter [aldodager](https://wordpress.org/support/users/aldodager/)
 * (@aldodager)
 * [16 years, 1 month ago](https://wordpress.org/support/topic/excluding-a-category-1/#post-1435314)
 * the code worked great!!!
    thank you very much!
 *  [ronvil](https://wordpress.org/support/users/ronvil/)
 * (@ronvil)
 * [15 years, 2 months ago](https://wordpress.org/support/topic/excluding-a-category-1/#post-1435510)
 * Sorry, but i’m just beginning to customize wordpress themes. how can i edit
 *     ```
       <?php
       foreach((get_the_category()) as $category) {
           if (!in_array($category->cat_name,array('cat1_to_exclude','cat2_to_exclude','cat3_to_exclude')) ) {
           echo '<a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a> ';
       }
       }
       ?>
       ```
   
 * to exlude the categories that i do not want to appear? Thank you in advance!
 *  [ronvil](https://wordpress.org/support/users/ronvil/)
 * (@ronvil)
 * [15 years, 2 months ago](https://wordpress.org/support/topic/excluding-a-category-1/#post-1435511)
 * Sorry for posting again. i would like to clarify my question above.
 * for example, i have the following categories
    1. Category 1
 *  1. Category 1.1
    2. Category 1.2
    3. Category 2
 * Then, under the post title, i want to put a link to the category archive for “
   Category 1.1” ONLY and not have the other categories of the same post appear.
   How do i do this? thanks again!

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Excluding a category’ is closed to new replies.

## Tags

 * [categories](https://wordpress.org/support/topic-tag/categories/)
 * [child category](https://wordpress.org/support/topic-tag/child-category/)
 * [exclude](https://wordpress.org/support/topic-tag/exclude/)
 * [exclude category](https://wordpress.org/support/topic-tag/exclude-category/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 4 replies
 * 3 participants
 * Last reply from: [ronvil](https://wordpress.org/support/users/ronvil/)
 * Last activity: [15 years, 2 months ago](https://wordpress.org/support/topic/excluding-a-category-1/#post-1435511)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
