0

I have a sidebar in wordpress registered like this:

    register_sidebar( array(
    'name'          => 'Blog Sidebar',
    'id'            => 'blog_sidebar',
    'before_widget' => '<div class="widget-wrapper col-xs-12 col-sm-6 col-md-6 col-lg-12">',
    'after_widget'  => '</div>',
    'before_title'  => '<h2 class="widget-title">',
    'after_title'   => '</h2>',
) );

Then, I'm dropping the tag cloud widget in there. It produces the widget code with title wrapped in <h2> and widget code wrapped in a <div> with classes above. So far, so good.

Now, I need to make some changes to how tag cloud is displayed, so I add a filter like so:

add_filter('widget_tag_cloud_args','set_tag_cloud_features');
  function set_tag_cloud_features($args) {
    $args = array(
        'smallest'    => 18, 
        'default' => 18, 
        'largest'    => 18, 
        'unit' => 'px',
        'show_count' => 1,
        'format' => 'list',
        'orderby' => 'count',
        'order' => 'DESC'
    );
    return $args;
}

Somehow this messes up the widget HTML now. <h2> and the widget wrapper <div> are gone. Looking at the wp_tag_cloud function reference, I don't see how to pass any arguments to avoid this... https://codex.wordpress.org/Function_Reference/wp_tag_cloud

  • 1
    With that filter, the $args includes the sidebar settings like before_widget - try var_dump($args);. So if you overwrite the entire array, you need to explicitly set the sidebar settings. Alternatively, override just those keys you wish to change their value - e.g. $args['smallest'] = 18;. – Sally CJ Feb 6 at 1:32
  • worked! if you post your answer I'll accept :P – geochanto Feb 6 at 1:50

Your Answer

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

Browse other questions tagged or ask your own question.