612-293-8629 HELLO@THEMIGHTYMO.COM

On a recent WordPress website project I was working on, I needed to remove specific categories from the list of categories that the “get_category()” function returns. Carl Bliss discovered the solution on the Technokinetics blog.

First, add the following to functions.php:

<?php
//Incomplete Category List to replace get_category()
//Adapted from: http://www.technokinetics.com/exclude-categories-from-the_category/
function incomplete_cat_list($separator) {
  $first_time = 1;
  foreach((get_the_category()) as $category) {
	if ($category->cat_name != 'CATEGORY TO EXCLUDE' && $category->cat_name != 'ANOTHER CATEGORY TO EXCLUDE') {
	  if ($first_time == 1) {
		echo '<a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>'  . $category->name.'</a>';
		$first_time = 0;
	  } else {
		echo $separator . '<a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a>';
	  }
	}
  }
}
?>

Make sure to replace the “CATEGORY TO EXCLUDE” text with your category’s nicename.

Then add the following to your theme:

<?php incomplete_cat_list(', ') ?>

That’s it!

PHONE, EMAIL, TEXT

We love to communicate: phone, email, text, Facebook, Twitter, LinkedIn, you name it.

LOCATIONS

PAYMENTS ACCEPTED

Call Now

Enroll in Our Free Beginner WordPress Class by Email

Never feel powerless in WordPress again!  Become a WordPress superstar for free in only minutes a day!

Our Beginner WordPress Email Class is delivered to your inbox!

Learn More 

You Have Successfully Enrolled! Prepare For Amazing!