I'm trying to hide specific categories from showing up on a portfolio home page. I was told that this was the concerned line of code on the php template file

<span class="entry-skills"><?php the_terms($post->ID, 'skill-type', '', ', ', ''); ?></span>

but there is no way to exclude certain types from this function by default. I would need to create a custom function in order to do so.

since I don't know much about php, I was thinking maybe some kind of expert could help me over here ? thanks

1 Answer 1


I haven't tested this, so it might need to be tweaked (specifically, I'm not sure if I got the names of the params right on the term object), but this should get you most of the way there.

//add filter
add_filter( 'get_the_terms', 'my_exclude_terms', 10, 1 );
//function to do filtering
function my_exclude_terms( $terms ) {
    //only filter for the homepage
    if( is_home() ) { // you may want to use is_front_page(), depending on your settings
        //list the unwanted terms
        $unwanted_terms = array( // fill this array with the unwanted term ids, slugs, or names
        // loop through the terms
        foreach( $terms as $k => $term ) {
            //only remove term if it's ID or slug is in the array.
              in_array( $term->term_id, $unwanted_terms, true ) || //comment out this line to remove term ID checking
              in_array( $term->slug, $unwanted_terms, true ) ||    //comment out this line to remove slug checking
              in_array( $term->name, $unwanted_terms, true )       //comment out this line to remove name checking
            ) {
                unset( $terms[$k] );
    return $terms;

I used the get_the_terms filter because it's the last filter before the terms are turned to HTML, which makes it significantly more difficult to parse. If you're a complete novice with PHP and need help troubleshooting or implementing, post a comment. Good luck!

  • hello thank-you so much this piece of code rocks and hides the skills from showing but it actually hides every type of categories, I was attempting to hide only a certain type of - I have deactivated it here for you to see (madu.fr/portfolio) actually it's only certain skills under each portfolio thumbs that I would like to hide - with the code you gave me it hides every type...
    – matt
    Jan 13, 2012 at 8:43
  • lol oops, I dropped a line of code, try it now.
    – mor7ifer
    Jan 13, 2012 at 14:36
  • nothing happens now :( function.php is the place to put that code right ? for example i'm trying to hide the "x da" cat witch has the id 126 - but nothing happens now with that new line...
    – matt
    Jan 13, 2012 at 18:04
  • did you update the $unwanted_terms array with the slugs or term ids for you unwanted terms? I'm going to check that $term->ID is correct real quick, but slugs should be working.
    – mor7ifer
    Jan 13, 2012 at 22:20
  • Turns out it's $term->term_id, so ids and slugs should both be working on that script.
    – mor7ifer
    Jan 13, 2012 at 22:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.