WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top
<div class="sidebar_area">
<div class="sidebar_content">
        <li><a href="#">This is new post</a></li>
        <li><a href="#">This is new post</a></li>
        <li><a href="#">This is new post</a></li>
        <li><a href="#">This is new post</a></li>
        <li><a href="#">This is new post</a></li>
        <li><a href="#">This is new post</a></li>

I like to make my widget like this code. But problem is here I can't use widget content like bellow. How can I give sidebar content div with "sidebar_area" class.

<div class="sidebar_area">
<div class="sidebar_content">
    <!-- content goes here -->

share|improve this question
Should this <div class="sidebar_area"> be the sidebar container or the widget container? And what do you mean with I can't use widget content like below? – tfrommen Jan 18 '14 at 13:08
widget container after title. – Hasanuzzaman Jan 18 '14 at 13:12
Hm? In your question you seem to be talking about sidebar_area, which comes before the title. So what is it? If you're looking for help here, you should consider writing more than just a short message... – tfrommen Jan 18 '14 at 13:15
Sorry, Just a mistake. It should be <div class="sidebar_content"> – Hasanuzzaman Jan 18 '14 at 13:17
up vote 1 down vote accepted

If I understood you correctly, this is what you are trying to achieve:

    'name' => 'Sidebar Name',
    'id' => 'sidebar-id',
    'before_widget' => '<div class="sidebar_area">',
    'before_title' => '<h4>',
    'after_title' => '</h4><div class="sidebar_content">',
    'after_widget' => '</div></div>',


share|improve this answer
It is ok. But problem is here if I don't use title in my sidebar widget than it will not work fine and create another problem. – Hasanuzzaman Jan 18 '14 at 13:27
Well, that's right. If you don't use titles at all, you can just move the second <div> into the before_widget parameter. If you use titles on some widgets, and not on some others, then there's no easy solution. – tfrommen Jan 18 '14 at 13:30
Really it is a limitation of WordPress. – Hasanuzzaman Jan 18 '14 at 13:37
Well, not really. You can do this. It's just not done with some parameters. You would have to hook into dynamic_sidebar_params, then check for your sidebar, and adjust the params according to whether a title is present or not. – tfrommen Jan 18 '14 at 13:43
hmm. Can you give me tutorial link about it . – Hasanuzzaman Jan 18 '14 at 13:50

Just register the sidebar and determine what to add before and after widget:

register_sidebar( array( 
    'name'          => __('My sidebar', 'cht'),
    'id'            => 'mysidebar',
    'class'         => 'sidebar_area',
    'before_widget' => '<div id="%1$s" class="sidebar_content %2$s">',
    'after_widget'  => "</div>\n",
    'before_title'  => '<h4>',
    'after_title'   => "</h4>\n"
share|improve this answer
"</div>\n" ?? What is n ? – Hasanuzzaman Jan 18 '14 at 13:22
UNIX end of a line - just... trust me it should be there. – Borek Jan 18 '14 at 13:24
How is the answer above better than mine - which BTW was posted 5 minutes earlier than the above one? – Borek Jan 18 '14 at 13:50
All that \n does is format the generated markup, which is pointless. You are never going to edit the generated markup so the only thing that formatting it does is increase the size of the file that has to be transmitted to the browser. – s_ha_dum Jan 18 '14 at 16:19

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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