I came up with an solution for not showing an sidebar in Wordpress when this is not filled with widgets. I did this by calling for the slug from the current page and named my sidebars the same as the slugs from my pages.
Thanks to some help I get this thing working but the problem is I see the name of the slug appears in front of the sidebar. For an image example Click here. For the live example Click here.
My current code is:
<?php if ( is_active_sidebar( the_slug() ) ) { ?>
<ul id="sidebar">
<?php get_sidebar(); ?>
</ul>
<?php } else { ?>
//empty
<?php } ?>
What goes wrong that causes this problem? Would be great to see the slug text disappear. Thanks already!
By default, the_slug()
outputs the value of the slug (via echo
), as well as returning it.
Simply pass false
(the_slug(false)
), so that the value is only returned and not echo
'd.