我喜欢“tosco”和“sanchothefat answers”这两种答案的想法,但我一直在为这种组合而挣扎,因为empty( $settings[ \'title\' ]
可能确实返回true如果未设置任何标题,小部件本身可能会输出默认标题。然后将此标题包装在before_title
和after_title
标记,然后再次分页符。一些默认小部件就是这样。
更容易坚持标准小部件注册参数;
register_sidebar(array(
\'id\' => \'sidebar1\',
\'name\' => __( \'Sidebar 1\', \'bonestheme\' ),
\'description\' => __( \'The first (primary) sidebar.\', \'bonestheme\' ),
\'before_widget\' => \'<div class="block">\',
\'after_widget\' => \'</div>\',
\'before_title\' => \'<div class="block-title">\',
\'after_title\' => \'</div>\',
));
然后根据Marventus的回答在此处添加过滤动作;
http://wordpress.org/support/topic/add-html-wrapper-around-widget-content
function widget_content_wrap($content) {
$content = \'<div class="block-content">\'.$content.\'</div>\';
return $content;
}
add_filter(\'widget_text\', \'widget_content_wrap\');