Guest User

Untitled

a guest
Jan 17th, 2019
419
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. function my_category_filter($cats){
  2. //exclude these from displaying
  3. $exclude = array("Large Announcement", "Announcement", "News");
  4. $Catds = array();
  5. foreach ($cats as$cat){
  6. if (!in_array($cat,$exclude)){$Catsa[] = $cat;}
  7. }
  8. return $Catsa;
  9. }
  10.  
  11. add_filter('the_category','my_category_filter');
  12.  
  13. function the_category_filter($thelist,$separator=' ') {
  14. // list the IDs of the categories to exclude
  15. $exclude = array(366);
  16. // create an empty array
  17. $exclude2 = array();
  18.  
  19. // loop through the excluded IDs and get their actual names
  20. foreach($exclude as $c) {
  21. // store the names in the second array
  22. $exclude2[] = get_cat_name($c);
  23. }
  24.  
  25. // get the list of categories for the current post
  26. $cats = explode($separator,$thelist);
  27. // create another empty array
  28. $newlist = array();
  29.  
  30. foreach($cats as $cat) {
  31. // remove the tags from each category
  32. $catname = trim(strip_tags($cat));
  33.  
  34. // check against the excluded categories
  35. if(!in_array($catname,$exclude2))
  36.  
  37. // if not in that list, add to the new array
  38. $newlist[] = $cat;
  39. }
  40. // return the new, shortened list
  41. return implode($separator,$newlist);
  42. }
  43.  
  44. // add the filter to 'the_category' tag
  45. add_filter('the_category','the_category_filter', 10, 2);
Add Comment
Please, Sign In to add comment