• Resolved bigfootnrg

    (@bigfootnrg)


    I’m trying to have my header say the user is logged in and give them the option to log in if they’re not. I’m really close. I’ve added this line of code beneath my header discription :

    <div class="description">
    
    <?php if ( $user_ID ) : ?>
    
    Logged in as
       <a href="<?php echo get_option('siteurl'); ?>/wp-admin/profile.php"><?php echo $user_identity; ?></a>
     .
       <a href="<?php echo get_option('siteurl'); ?>/wp-login.php?action=logout" title="Log out of this account">
     Logout
       &raquo;</a>
    
    <?php else : ?>
    
       <a href="<?php echo get_option('siteurl'); ?>/wp-login.php?redirect_to=<?php echo urlencode(get_permalink()); ?>">
       Log in</a>
        ||
       <a href="wp-login.php?action=register">
       Register</a>
    
    <?php endif; ?>
    
    </div>

    I have weird spacing on this post for demonstration purposes.

    The code is a modification of the code for commenting when logging in is required. The thing works beautifully except that the $user_identity doesn’t echo/report/display or whatever. If logged in it says “Logged in as . Logout ?” instead of “Logged in as <username>. Logout ?”

    I’m far from learned in php, so this could be a misplaced comma on my part or it could be impossible. Any insight and help is greatly appriciated.

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

    (@bigfootnrg)

    figured it out, needed to make the variable global. This code worked:
    <?php global $user_identity; echo $user_identity; ?>

    Thanks

Viewing 1 replies (of 1 total)
  • The topic ‘1 line of code issue.’ is closed to new replies.