3

How do I remove a particular tag name from the tag cloud ?

I changed wp-includes/default-widgets.php on line 1038 from

wp_tag_cloud( apply_filters('widget_tag_cloud_args', array('taxonomy' => $current_taxonomy) ) );

to

wp_tag_cloud( apply_filters('widget_tag_cloud_args', array('taxonomy' => $current_taxonomy, 'exclude' => "featured") ) );

But no effect.

5 Answers 5

6

First: Don’t touch the core files, they will be overwritten during the next update.

There is already an argument for exclusions available: exclude. It expects a term id.

Sample:

wp_tag_cloud(
    array (
        'exclude' => 54
    )
);

Sometimes you don’t know the ID, but you can get it if you know the slug:

$args = array ();
$ex_term = get_term_by( 'slug', 'chattels', 'post_tag' );

if ( ! empty ( $ex_term ) && ! is_wp_error( $ex_term ) )
    $args['exclude'] = $ex_term->term_id;

wp_tag_cloud( $args );

See the Codex page for more parameters.

1
  • This works well if calling the wp_tag_cloud() function directly, but not if using the Tag Cloud widget
    – shea
    Dec 25, 2012 at 21:40
3

Modifying core files is not recommended as they will be overwritten in the next upgrade. Fortunately, you can use the power of filters to make the change you need.

The reason why your hack didn't work is because you need to pass the tag id to the function, not the name.

This code will modify the tag cloud args to exclude the tag with the 'featured' slug. Paste this code to your active theme's functions.php file, a custom plugin, or as a code snippet:

add_filter( 'widget_tag_cloud_args', function ( $args ) {
    $args['exclude'] = get_term_by( 'slug', 'featured', 'post_tag' );
    return $args;
} );
1

I wanted to remove multiple tags. This is what I did:

add_filter( 'widget_tag_cloud_args', 'bb_exclude_tag');
function bb_exclude_tag( $args ) {
    $args[ 'exclude' ] = '234, 249, 255, 221, 223, 225, 209, 264, 243, 211, 236, 240, 215, 227, 232, 253';
    return $args;
}
0

You are passing name, you ll need to pass ID of that tag.

wp_tag_cloud( apply_filters('widget_tag_cloud_args', array('taxonomy' => $current_taxonomy, 'exclude' => "5") ) );

0

I guess that many people like me will get here as result of searching for how to do the same thing in Woocommerce.

The current solution to exclude tags from the Woocommerce tag cloud:

/* exclude woocommerce product tags from the shops tag cloud */
function customized_exclude_wc_widget_tags($cat_args) {
    $cat_args['exclude'] = array('141','142','143');
    return $cat_args;
}
add_filter('woocommerce_product_tag_cloud_widget_args', 'customized_exclude_wc_widget_tags');

DO NOT MODIFY YOUR THEME/PLUGIN FILES:

  1. Download the "Code Snippets" plugin and activate it
  2. select Snippets, new snippet
  3. insert a title for the snippet like "filter out tags from woocommerce tag cloud"
  4. paste the above code
  5. customize the numbers in the array to match the ids of the tags you want to filter out
  6. select "execute snippet on front-end only"
  7. save and activate the snippet
  8. go at the shop's tag cloud and find the tags listed in the array are now hidden.

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.