Search code examples
wordpressfilterwidgettitle

Apply widget_title filter only to WordPress widgets from a certain sidebar?


I need to apply the widget_title filter only to the widgets from a certain sidebar. If the widget is from "footer" I want to apply:

function widget_title_empty($output='') {
    if ($output == '') {
        return ' ';
    }
    return $output;
}
add_filter('widget_title', 'widget_title_empty');

to it.

Thanks.


Solution

  • Since you want to use a hardcoded sidebar name I assume perhaps you are creating a theme and have control over the code that prints the sidebar? If so, you could first add the filter and then remove it again, like this:

    add_filter('widget_title', 'widget_title_empty');
    dynamic_sidebar('footer');
    remove_filter('widget_title', 'widget_title_empty');
    

    This way, surrounding sidebars won't be affected.