Hide certain tags on Product Edit tag cloud

On my site I now have over 800 different product tags. When adding products it takes a very long time to scroll through them all to tag them. I tried to target specific product tags in CSS with display:none; but it isn’t working. Ideally I’d like to only show a specific 30 tags and omit the rest from the “choose the most used tag” box. This is what I have so far. I know I’m close. If anyone could offer some direction. It would be greatly appreciated

#tagcloud-product_tag > ul > li:nth-child(1) > a {display: none !important;}

1 Answer
1

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