Skip to content
Advertisement

if and else statement just not working

Here is my if statement. I’m trying to have two differnt options. One is if the user is logged in and the other of course if they’re not. For the life of me I can not get these to work. This is a Word Press site.. Any help here would be awesome. Here is what I have.

<div class="btn btn-success">
        <?php if( ! is_user_logged_in()): ?> 
        <a href="<?php echo $submit_question_link ?>"<?php _e('Ask a question','dwqa') ?></a>           
    } else { 
        <?php add_modal_login_button( $login_text = 'Login to Ask a Question', $logout_text = 'Logout', $logout_url = '', $show_admin = false ); ?><?php endif; } ?>            
            </div>

Advertisement

Answer

        <div class="btn btn-success">
        <?php if( ! is_user_logged_in()): ?> 
        <a href="<?php echo $submit_question_link ?>"<?php _e('Ask a question','dwqa') ?></a>           
     <? else: ?>
        <?php add_modal_login_button( $login_text = 'Login to Ask a Question', $logout_text = 'Logout', $logout_url = '', $show_admin = false ); ?><?php endif; ?>            
            </div>

You have completely wrong syntax. Your } else { isn’t even in PHP tags and the alternative syntax that you are using doesn’t require braces.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement