4

I have over 100 tags on my blog, but in the tag cloud there's less that 50. I don't really care about that, but I want to align the widgets in the blog footer, so I need to add 10 or 20 more tags to the cloud. Is there a way to do it?

2 Answers 2

8

The tag cloud widget uses wp_tag_cloud() to display the tags, which defaults to 45 tags.

Source: https://developer.wordpress.org/reference/functions/wp_tag_cloud/

One can use the widget_tag_cloud_args filter to change this number (and any other arguments passed to wp_tag_cloud(). Here's an example:

function wpse_235908_tag_cloud_args( $args ) {
    $args['number'] = 70; // the number of tags you want to display.
    return $args;
}
add_filter( 'widget_tag_cloud_args', 'wpse_235908_tag_cloud_args' );

You can add this piece of code in a custom plugin or your theme's function.php file for example.

Note: There's also a doc reference for the widget_tag_cloud_args filter, but the documentation is currently wrong as per this core ticket.

0
0

To increase the number of tags displayed by the Tag Cloud widget, you can add in functions.php the code below (testing in WordPress 6.1.1)

function render_block_data_aleksvgrig($parsed_block) {
    if (isset($parsed_block['blockName']) && $parsed_block['blockName'] === 'core/tag-cloud') {
        //Let's change the number of displayed tags.
        //If you do not change the limit on the maximum number of tags, then the value will be automatically reset to the default value (45)
        //in method WP_Block_Type::prepare_attributes_for_render
        $parsed_block['attrs']['numberOfTags'] = 1000;
    }
    return $parsed_block;
}

function block_type_metadata_aleksvgrig($metadata) {
    if (isset($metadata['name']) && $metadata['name'] === 'core/tag-cloud') {
        //Change the limit on the maximum number of tags (default 100)
        //For validation in method WP_Block_Type::prepare_attributes_for_render
        $metadata['attributes']['numberOfTags']['maximum'] = 1000;
    }
    return $metadata;
}

add_filter('render_block_data', 'render_block_data_aleksvgrig');
add_filter('block_type_metadata', 'block_type_metadata_aleksvgrig');

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.