logo

This is an old version of this answer!

Return to the current answer
that's right, we need the sidebar id to use is_active_sidebar()...

so this should be working now (!)

copy/paste this in your function.php :

// Register widgets area(s)
if ( function_exists('register_sidebar') ){
$sidebars = array(
'Footer Widgets',
'another widget area'
);
foreach($sidebars as $sidebar):
register_sidebar(array(
'name'=>$sidebar,
'before_widget' => '<li id="%1$s" class="widget widget-%2$s">',
'after_widget' => '</li>',
'before_title' => '<h4 class="widgettitle">',
'after_title' => '</h4>'
));
endforeach;
}

/**
* Get a sidebar id by name.
*
* @param string $name Widget name.
* @return string Widget id, if widget sidebar with that name was found. Empty if not found.
*/

function get_sidebar_id_by_name( $name='' ) {
// no name specified !
if ( '' == $name ) return '';

global $wp_registered_sidebars;

// no registered sidebar !
if ( !isset( $wp_registered_sidebars ) ) return '';

foreach ( $wp_registered_sidebars as $sidebar ):
if ( $name == $sidebar['name'] ) return $sidebar['id'];
endforeach;

return '';
}


and this in your footer.php :

<div id="footer">
<?php if ( function_exists( 'dynamic_sidebar' ) && function_exists( 'is_active_sidebar' ) && is_active_sidebar( get_sidebar_id_by_name( 'Footer Widgets' ) ) ) { ?>
<ul id="footer-widgets">
<?php dynamic_sidebar( 'Footer Widgets' ) ?>
</ul><!-- /#footer-widgets -->
<?php } ?>
</div><!-- /#footer -->

Sébastien Méric | 12/14/09 at 9:41am

This is an old version of this answer!

Return to the current answer