I'm trying to reset the font size for tag cloud by using the widget_tag_cloud_args filter as follows:

add_filter( 'widget_tag_cloud_args', 'filter_tag_cloud_widget' );
function filter_tag_cloud_widget() {
    $args = array(
        'smallest'  => 16,
        'largest'   => 16,
        'unit'      => 'px'
    return $args;

This should set the font size for all the tags to 16px. The code does its job, but now there is an issue. The <div class="tagcloud"> ... </div>wrapper for tag cloud is gone. The anchors are directly output in the sidebar like this:

<a href="/tag-path/" class="tag-cloud-link tag-link-32 tag-link-position-2" style="font-size: 16px;" aria-label="tag">tag</a>

What am I doing wrong?


You're overwriting the defaults passed to the filter, one of which is echo, which is false by default for the widget. This is because the function that generates the tag cloud has echo equal to true by default, so your tag cloud is getting immediately output instead of returned back to the widget handler.


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.