Hide certain tags on Product Edit tag cloud

You can add a filter via the theme’s functions.php file (I’d recommend you use a child-theme for customizations, but that’s outside the scope of this question)

The following will limit the tag-cloud in the wp-admin backend to the first 5.

function tryme($tag_data){
    $short_tag_data = array_slice($tag_data, 0, 5, true);
    return $short_tag_data;
}
add_filter( 'wp_generate_tag_cloud_data', 'tryme' );

We can take this a step further & allow only specific tags…

function tryagain($tag_data){
    $only_these_tags = array( 'keep-this-tag', 'and-this-tag' ); // A list of the slugs of the tags we want to keep
    $short_tag_data = array(); // an empty placeholder for our new array
    foreach ( $tag_data as $tag ) {
        if ( in_array ( $tag['slug'], $only_these_tags ) ) {
            array_push( $short_tag_data, $tag );
        }
    }
    return $short_tag_data;
}
add_filter( 'wp_generate_tag_cloud_data', 'tryagain' );

Leave a Comment