inovve

Wordpress - Exclude categories from the_category function

Feb 22nd, 2013
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. Need a PHP and Wordpress expert? Go to www.inovve.com
  2.  
  3. For Instance you don’t want to show the category Uncategorized and Private, in order to do so first put the paste code at the end of your functions.php located in your current theme folder.
  4.  
  5. function the_category_filter($thelist,$separator=' ') {
  6. if(!defined('WP_ADMIN')) {
  7. //Category Names to exclude
  8. $exclude = array('Uncategorized', 'Private');
  9.  
  10. $cats = explode($separator,$thelist);
  11. $newlist = array();
  12. foreach($cats as $cat) {
  13. $catname = trim(strip_tags($cat));
  14. if(!in_array($catname,$exclude))
  15. $newlist[] = $cat;
  16. }
  17. return implode($separator,$newlist);
  18. } else {
  19. return $thelist;
  20. }
  21. }
  22. add_filter('the_category','the_category_filter', 10, 2);
Advertisement
Add Comment
Please, Sign In to add comment