3

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;}
2

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' );
  • Brilliant! that worked like a charm! Thanks a lot! I went with only allowing specific tags. Wordpress is oh so customizable. – Suno360 Jan 20 at 13:11
  • Happy to help you save some time & bandwidth. If a question here, or on any StackExchange site helps. Please do upvote & accept the answer. – admcfajn Jan 20 at 17:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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