问题
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.
}
回答1:
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.
回答2:
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
回答3:
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' => ' -->',
) );
回答4:
Or you can make it even more simple by doing this in functions:
'before_title' => '<span style="display: none;">',
'after_title' => '</span>',
回答5:
Is there a title field for the widget you are using?
You could try just putting
in there, so you get a space for the title.
Not the most elegant solution though.
回答6:
couldn't you just do display: none;
in the css for widget-title?
回答7:
Please put this code in functions.php file.
add_filter( 'widget_title', 'remove_widget_title' );
function remove_widget_title( $widget_title ) {
return $widget_title == ' ' ? '' : $widget_title;
}
来源:https://stackoverflow.com/questions/9428758/wordpress-dynamic-sidebar-without-title