• reddo

    (@reddo)


    I’m working on a template which requires me to have different classes on a div, depending on 2 sidebars. If one or both of the sidebars are inactive, meaning has no widgets (not talking about widgets with no output), the respective div should have different classes. It’s all working, exccept one instance…

    My code is:

    <?php
    $ltActive = is_active_sidebar('lt');
    $rtActive = is_active_sidebar('rt');
    
    if($ltActive && $rtActive){
      $class = 'grid_6';
    
    }elseif(!$ltActive && !$rtActive){
      $class = 'grid_12';
    
    }else{
      $class = 'grid_9';      // <==
    }
    ?>
    
    <div class="<?php echo $class; ?> eqh">

    If both the sidebars are active it’s working, if none of the sidebars are active it’s working, if the rt sdebar is active and the lt sidebar is not, it’s working, but if the lt is active and the rt is not, it’s not working.

    Also, I’m only displaying the divs containing the sidebars if there are active widgets in it, and that’s working (O.o), meaning, it doesn’t display the rt sidebar.

    I’ve echoed the state of the sidebars with <p>right sidebar: <?php echo is_active_sidebar('rt') ?> and left sidebar: <?php echo is_active_sidebar('lt') ?></p> and I get different values within the same page… Ceck it out here: https://kendallellis.co/energy-and-infrastructure/

    Someone tell me what the hell is going on PLEASE!!

Viewing 1 replies (of 1 total)
  • Thread Starter reddo

    (@reddo)

    Seems like no one cares enough to give me an answer. I’ve found a workaround this BUG, but it’s not as elegant as I’d wished.

    It looks like the is_active_sidebar() function works as expected ONLY in sidebar-***.php or sidebar.php and only before calling dynamic_sidebar(). After that it just returns true no matter what.

    This is how i got it to work:

    <?php
    $ltActive = is_active_sidebar('lt');
    $rtActive = is_active_sidebar('rt');
    
    if($ltActive && $rtActive){
      $class = 'grid_6';
    
    }elseif(!$ltActive && !$rtActive){
      $class = 'grid_12';
    
    }else{
      $class = 'grid_9';
    }
    ?>
    <?php if( is_active_sidebar(lt)) : ?>
      <div class="grid_3 left eqh">
    <?php dynamic_sidebar(lt); ?>
      </div><!-- grid_3 -->
    <?php endif; ?>
    
    <div class="<?php echo $class; ?> eqh">

    Thanks for all the help I didn’t get.

Viewing 1 replies (of 1 total)
  • The topic ‘is_active_sidebar() returning different values’ is closed to new replies.