[resolved] 1 line of code issue. (2 posts)

  1. bigfootnrg
    Posted 8 years ago #

    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">
    <?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">
    <?php endif; ?>

    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.

  2. bigfootnrg
    Posted 8 years ago #

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


Topic Closed

This topic has been closed to new replies.

About this Topic