WordPress : Simple php IF statement not processing

can someone explain why the else statement is not working in WordPress for the sidebar.php?

<?php if(is_front_page() ) : ?>

 **content shows on main page sidebar**

<?php elseif(!is_front_page() ) : ?>
<?php // else: ?> // tried **else:** also

 **some content**
 **nothing is shown on any other page...**

<?php endif;?>

Related posts

Leave a Reply

2 comments

  1. The is_front_page() conditional will always return false if it is used inside the loop or after the loop has ran (like in a sidebar). You can call wp_reset_query(); after your loop to reset the page query_vars.

    See this answer on WPSE for more info.

  2. Im not sure if is_front_page() exists, but just use {} around each condition result:

    <?php if(is_front_page() ) { ?>
    
     **content shows on main page sidebar**
    
    <?php } else { ?>
     // tried **else:** also
    
     **some content**
     **nothing is shown on any other page...**
    
    <?php } ?>