I am using bootstrap to create panels for the sidebar widgets, and I can set the container markup for the widget, as well as the markup for the panel header, but I cannot provide the markup for the panel content. I have this so far:

    'name' => __('Right Sidebar'),
    'id' => 'home_right_1',
    'before_widget' => '<div class="panel panel-default">',
    'after_widget' => '</div>',
    'before_title' => '<div class="panel-heading"><h3 class="panel-title">',
    'after_title' => '</h3></div>'

bootstrap panels need to look like this:

<div class="panel panel-default">
  <div class="panel-heading">Panel heading without title</div>
  <div class="panel-body">
    Panel content

How can I add the '<div class="panel-body">###</div>' to each widget?

2 Answers 2



  • opening <div class="panel-body"> to the end of after_title
  • closing </div> to the start of after_widget.

I know this post is somewhat older, but I thought I would point out that the previous answer only works if there is always a title.

If you want to make sure that only the content of the widget gets wrapped in a panel-body class, you might want to try something like this:

function my_widget_content_wrap($content) {
    $content = '<div class="panel-body">'.$content.'</div>';
    return $content;
add_filter('widget_text', 'my_widget_content_wrap');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.