function exclude_post_categories($excl='', $spacer=''){ $categories = get_the_category($post->ID); if(!empty($categories)){ $exclude=$excl; $exclude = explode(",", $exclude); foreach ($categories as $child){ $parents = get_category_parents($child->cat_ID, FALSE, ','); $parents = explode(',', $parents); foreach($exclude as $excluded){ if (in_array($excluded, $parents)){ $excluded_children[] = $child->cat_ID; } } } $thecount = count(get_the_category()) - count($excluded_children); foreach ($categories as $cat) { $html = ''; if(!in_array($cat->cat_ID, $excluded_children)) { $html .= 'cat_name . '">' . $cat->cat_name . ''; if($thecount>1){ $html .= $spacer; } $thecount--; echo $html; } } } }