2

In the codex example of displaying sidebars, what is the significance of the conditional wrapping around the call to dynamic_sidebar? Why do this:

<?php if ( dynamic_sidebar('example_widget_area_name') ) : else : endif; ?>

this seems to work ok:

<?php dynamic_sidebar('example_widget_area_name'); ?>

Thanks,

Toby

1 Answer 1

3

To quote the Codex

The return value should be used to determine whether to display a static sidebar. This ensures that your theme will look good even when the Widgets plug-in is not active.

So essentially you can use is to display other content if the user has not activated any widgets in the sidebar.

3
  • Thanks for the reply, that helps. So if my theme should only display the sidebar (or nothing) it's ok to skip the conditional stuff? Mar 19, 2014 at 20:27
  • Yes that's absolutely fine, it's just been the convention to include a conditional statement in case you want other content should the user not have any widgets active
    – MBL
    Mar 19, 2014 at 21:54
  • It's a holdover from the time when the widgets system was a plugin and not built into WordPress. It is not strictly necessary any longer.
    – Otto
    Mar 20, 2014 at 1:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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