Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9311471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T01:22:26+00:00 2026-06-19T01:22:26+00:00

I have this code: <?php if ( is_active_sidebar(‘lt’) && is_active_sidebar(‘rt’)) { ?> <div class=grid_6

  • 0

I have this code:

<?php if ( is_active_sidebar('lt') && is_active_sidebar('rt')) { ?>

  <div class="grid_6 eqh">

<?php } elseif ( !is_active_sidebar('lt') || !is_active_sidebar('rt')) { ?>

  <div class="grid_9 eqh">

<?php } elseif ( !is_active_sidebar('lt') && !is_active_sidebar('rt')) { ?>

  <div class="grid_12 eqh">

<?php }; ?>

It’s part of a wordpress theme I’m developing. It’s supposed to show different classes according to a sidebar being active or not. The response I get from wp if a sidebar is active is 1 and NULL if it isn’t. It works if the ‘lt’ sidebar is active, but the ‘rt’ is not, it diplays the ‘grid_9’ div, if none of the sidebars is active, it displays the ‘grid_12’ div, but if the ‘rt’ sidebar is inactive and the ‘lt’ is active, it still displays the ‘grid_6’ div. If I remove the 1st if statement:

<?php if ( is_active_sidebar('lt') && is_active_sidebar('rt')) { ?>

it doesn’t display any of the divs.

I’ve tried every combination that came to my mind, I’ve separated the:

<?php } elseif ( !is_active_sidebar('lt') || !is_active_sidebar('rt')) { ?>

statement in 2 different ones, tried separate if statements without ‘elseif’, tried with, ‘AND’ and ‘OR’ instead of ‘&&’ and ‘||’ and a whole bunch of other variations, but nothing worked.

If anyone can help me or at least pont me in the right direction, I’d be very grateful.

As per @one-trick-pony ‘s suggestion, code is now:

<?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">

The php code is working, but it seems there is a bug with the is_active_sidebar() function in WP, but they are ignoring my question on the WP support forum.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-19T01:22:28+00:00Added an answer on June 19, 2026 at 1:22 am

    First, put the return result in variables (it will speed up processing a little):

    $ltActive = is_active_sidebar('lt');
    $rtActive = is_active_sidebar('rt');
    

    Now, the problem is in your 2nd condition – you’re checking if any of the sidebars are inactive, and if one of them or both are, the 3rd condition will never be evaluated.

    So:

    (!$ltActive && !$rtActive)
    

    must go before:

    (!$ltActive || !$rtActive)
    

    (last condition will not be necessary, you can just leave else{...})


    Ok here’s the code:

    if($ltActive && $rtActive){
      $class = 'class when both sidebars are active';
    
    }else(!$ltActive && !$rtActive){
      $class = 'class when both sidebars are inactive';
    
    }else{
      $class = 'class when only one of the sidebars is active (either one)';      
    }
    
    ?>
    <div class="<?= $class; ?>">
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code below: <li> <a href=<?php echo base_url()?>home/promos/call class=promo-call active-call></a> </li> <li>
I have this piece of code in my cms: <ul class=subsection_tabs id=tab_group_one style=clear:none;> <?php
I have this code: <div id=menu> <ul> <li><span id=menulabel>Your Languages</span></li> <?php $hotClass = '';
I have this code which is passed to Paypal checkout: <?php foreach ($paypalBasket as
Ok I have this code: //this is the hi.php// <?php //highlight items// $con =
I have this code: <INPUT type=button value=Pre-Requisites onClick=window.open('pre_requisites.php','pre-requisites','width=670px,height=470px,left=0px,top=100px,screenX=0,screenY=100')> It is use to open a
this is function.php of a wordpress theme that NOD32 says this code have a
This is my php code (I already have a connection to the db): $result
This is the PHP code I have. function decrypt($s_input, $s_key, $s_iv) { $s_decrypted =
I have this code in PHP writing views to a text-file and just increasing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.