is_active_sidebar() not working

why the is_active_sidebar() function return always false?

Function.php code:

if ( function_exists('register_sidebar') ) {   
register_sidebar(array( 
    'name' => 'Footer Column 2',
    'id' => 'footer-column-2', // I also added the ID but doesn't work 
    'before_widget' => '<div id="%1$s" class="omc-footer-widget %2$s">',    
    'after_widget' => '</div>', 
    'before_title' => '<h4>',   
    'after_title' => '</h4>'   
));
}

footer.php code:

<?php if ( is_active_sidebar( 'footer-column-2' ) ) : ?>    

    <div class="omc-footer-widget-column">  

            <?php dynamic_sidebar( 'Footer Column 2' ); ?>

    </div><!--- /second-footer-column -->

<?php endif; ?>

I tried with the name or id but not working.
Any idea?

Thanks

EDITED:
I have more dynamic sidebars and I use this code to register these:

//register custom sidebars
add_action( 'widgets_init', 'register_theme_sidebars_dynamic' );

// and this function...I think the problem is here:

function register_theme_sidebars_dynamic(){
    global $wpdb;
    //post and pages sidebars
    $widgetized_pages = $wpdb->get_col($wpdb->prepare("SELECT DISTINCT meta_value FROM $wpdb->postmeta WHERE meta_key = 'omc_page_sidebar'", ''));

    if($widgetized_pages){
        foreach($widgetized_pages as $w_page){
            $widget_id = strtolower(str_replace(' ', '_', $w_page));
            register_sidebar(array(
                'name' => $w_page,
                'id'   => 'jw_widgetsection_'.$widget_id,
                'description'   => '',
                'before_widget' => '',
                'after_widget' => '',
                'before_title' => '',
                'after_title' => ''
            ));
         }// For each
    }//End If


   }


1 Answer
1

Try this in your functions.php

function your_widget(){

register_sidebar(array( 
    'name' => 'Footer Column 2',
    'id' => 'footer-column-2', // I also added the ID but doesn't work 
    'before_widget' => '<div id="%1$s" class="omc-footer-widget %2$s">',    
    'after_widget' => '</div>', 
    'before_title' => '<h4>',   
    'after_title' => '</h4>'   
));

}

add_action( 'widgets_init', 'your_widget' );

Call in footer.php with the ID.

<?php if ( is_active_sidebar( 'footer-column-2' ) ) : ?>    

    <div class="omc-footer-widget-column">  

            <?php dynamic_sidebar( 'footer-column-2' ); ?>

    </div><!--- /second-footer-column -->

<?php endif; ?>

Leave a Comment