Wordpress dynamic sidebar without title

I'd like to pull in a dynamic sidebar. I have 1 text item in the widget sidebar but I DON't want to pull in widget the title (just the body). Can anyone show me where WordPress is pulling in the Title?

e.g. At the moment I have...

// In my page template...
<div id='advert-header'>        
   <?php dynamic_sidebar( 'Header Advert' ); ?>
</div>

// In functions.php...
function twentyten_widgets_init() {
    register_sidebar( array(
        'name' => __( 'Header Advert', 'twentyten' ),
        'id' => 'primary-widget-area',
        'description' => __( 'The primary widget area', 'twentyten' ),
        'before_widget' => '',
        'after_widget' => '',
        'before_title' => '',
        'after_title' => '',
    ) );
// etc.
}

Answers


You can try this (in functions.php within register_sidebar)

'before_title' => '<span class="hidden">',
'after_title' => '</span>',

And Css

.hidden{display:none;}

You can also try this.


Widget always have a filter applied on title name 'widget_title', use that.

add_filter('widget_title','my_widget_title'); 
function my_widget_title($t)
{

    return null;
}

Thanks

-Shak


Those titles can be useful for CMS user, so in your register_sidebar, you can put sth. like I did in code below (works in Wordpress 5.0.3). Now widgets title is in html comment, it seems ok for me

  register_sidebar( array(
    'name'          => esc_html__( 'Contact page widgets', 'xxx' ),
    'id'            => 'sidebar-3',
    'description'   => esc_html__( 'Add widgets here to appear on contact page.', 'xxx' ),
    'before_widget' => '<div id="%1$s" class="widget %2$s">',
    'after_widget'  => '</div>',
    'before_title'  => '<!-- ',
    'after_title'   => ' -->',
) );

Or you can make it even more simple by doing this in functions:

'before_title' => '<span style="display: none;">',
'after_title' => '</span>',

Is there a title field for the widget you are using? You could try just putting &nbsp; in there, so you get a space for the title. Not the most elegant solution though.


couldn't you just do display: none; in the css for widget-title?


Please put this code in functions.php file.

add_filter( 'widget_title', 'remove_widget_title' );
function remove_widget_title( $widget_title ) {
    return $widget_title == '&nbsp;' ? '' : $widget_title;
}

Need Your Help

user vs sudo vs sudo_user in ansible playbooks

sudo ansible

I have read the Ansible documentation but I am still a bit confused about the three following parameters in ansible playbooks: user, sudo, sudo_user.