Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am trying to create a new sidebar. For that I have used the following code:

In functions.php

if ( function_exists('register_sidebar') )
register_sidebar();

if ( function_exists ('register_sidebar')) {
register_sidebar ('sidebar-custom');
} 

Then I created a file called sidebar-custom.php.The code for that file is as follows

<ul class=”sidebar”>
     <?php if ( !function_exists('dynamic_sidebar') ||
           !dynamic_sidebar('sidebar-custom') ) : ?>
     <?php endif; ?>
</ul>

But the sidebar area is not visible in the dashboard.I know I have done something terribly wrong. But dont know what it is. Can anyone help?

share|improve this question
add comment

1 Answer

Two problems. To register the sidebar you need to pass a minimum of the 'id'.

if ( function_exists ('register_sidebar')) {
  register_sidebar(array('id'=>'custom'));
}

Despite the Codex, I cannot get the sidebar to show up using only register_sidebar('custom');

That will make the sidebar show up on the backend. See the Codex for other parameters.

Secondly, there is nothing to load sidebar-custom.php. dynamic_sidebar('custom') would load a file named sidebar-custom.php, at least the Codex appears to suggest that, but since you have that function call inside sidebar-custom.php it never gets to run.

Third, you have curly quotes in you code. Look at the quotes around the class name.

So, to make this work put the following in functions.php (same as above):

if ( function_exists ('register_sidebar')) {
  register_sidebar(array('id'=>'custom'));
} 

Place the following in the template file where you want to the sidebar to load but not in sidebar-custom.php.

 if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('custom') ) :
 endif;

Your sidebar should now work, but again despite the Codex or possibly the Codex is just very confusing on the point, I can't get your sidebar-custom.php file to load.

To do that I have to explicitly use get_sidebar ('custom');

The more I worked on this, the more I came to believe that the Codex is poorly written when it come to custom sidebar files. The truth is in there but it is hard to see. Hope this helps.

share|improve this answer
add comment

Your Answer

 
discard

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.