• Someone posted this brilliant solution to exclude categories from the_category (placed in functions.php of theme).

    function the_category_filter($thelist,$separator=' ') {
    	if(!defined('WP_ADMIN')) {
    		//list the category names to exclude
    		$exclude = array('Something','Something Else','Blah','YAY');
    		$cats = explode($separator,$thelist);
    		$newlist = array();
    		foreach($cats as $cat) {
    			$catname = trim(strip_tags($cat));
    			if(!in_array($catname,$exclude))
    				$newlist[] = $cat;
    		}
    		return implode($separator,$newlist);
    	} else
    		return $thelist;
    }
    add_filter('the_category','the_category_filter',10,2);

    Questions:
    1. How can I change to this exclude by category ID instead of by category name?
    2. Is there way to automatically exclude subcategories/children of the excluded categories? (i.e., without explicity listing all of the subcats)

Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Exclude subcategories from the_category’ is closed to new replies.