Exclude Category from Post’s Category List

For some reason, maybe you want to exclude one or two categories for the list. This can be achieved by hacking the_category function, or create a new code to list the category, to replace the_category. <?phpforeach ((get_the_category()) as $category) {if ( $category ->cat_name != 'cat_to_exclude') {echo'<a href="'. get_category_link( $category->term_id ) .'" title="'. sprintf( __( "View all posts in %s" ), $category->name ) . '"' . '>'. $category->name.'</a> ';}}?>