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'); ?>



1 Answer 1


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.

  • 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? Commented 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
    Commented 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
    Commented Mar 20, 2014 at 1:22

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.