0

hi i'm using the Categories widget show hierarchy. I leave the space for title because I don't need to show any title. but it then displays on the website as "Categories". how can I remove that?

1

There is a filter you can use to do this. (Kruti has even found it, but instead of using it, he modified core files...)

$title = apply_filters('widget_title', empty( $instance['title'] ) ? __( 'Categories' ) : $instance['title'], $instance, $this->id_base);

So what you really need to do, is to add this to your functions.php:

function my_repair_categories_empty_title($title, $instance, $base) {
    if ( $base == 'categories' ) {
        if ( trim($instance['title']) == '' )
            return '';
    }
    return $title;
}
add_filter('widget_title', 'my_repair_categories_empty_title', 10, 3);
  • i added this code in functions.php and it works well. but i have a doubt.is this function affect any other widget's title in future??sorry if my doubt is unnecessary. – Zammuuz Nov 26 '13 at 10:40
  • It will affect any categories widget. No other widgets should be affected. – Krzysiek Dróżdż Nov 26 '13 at 11:17
0

add_filter for widget_title does not allow more than one parameter when called so the above will throw PHP warnings.

This seems to work instead:

function my_repair_categories_empty_title() {
    if ( $base == 'categories' ) {
        if ( trim($instance['title']) == '' )
            return '';
    }
    return $title;
}
add_filter('widget_title', 'my_repair_categories_empty_title');

(tried to add this as a Comment to Krzysiek Dróżdż but don't have enough rep to do so)

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.