Support » Themes and Templates » How to hide widget title when empty?

  • How do I go about hiding a widget’s title tags when the widget’s title is empty? Currently my theme is leaving an empty title box which looks horrible when nothing’s in it.

    Any help would be greatly appreciated.

Viewing 3 replies - 1 through 3 (of 3 total)
  • which theme are you using?

    link to your site?

    Theme is still being developed. Not available online. But I am registering the following code for my sidebar:

    'name' => 'Sidebar',
    'before_widget' => '<section class="widget widget-sidebar">',
    'after_widget' => '</section>',
    'before_title' => '<h1>',
    'after_title' => '</h1>'

    I need the H1 tags to be stripped when there is no content.

    Having the same problem.

    To remove the empty line and margin you could use the following workaround:

    function widget_empty_title($output='') {
    	if ($output == '') {
    		return '<span class="empty">&nbsp;</span>';
    	return $output;
    add_filter('widget_title', 'widget_empty_title');


    .widget .empty {
    	display: block;
    	height: 1em;
    	margin-bottom: -2em; /* Assuming the h1 has a margin-bottom of 1em and the line-height is 1 */

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to hide widget title when empty?’ is closed to new replies.