0

I'm trying to show the User's Name in a login button at the top of our page. I tried to base it off of this advice, but it's just showing the PHP code. Specifically, I'd like "My Account" to change to "Welcome {UserName}. How do I display logged-in username IF logged-in?

                <?php global $current_user; wp_get_current_user(); ?>
                <?php if (!is_user_logged_in()) :?>
                    <a href="/member-login/" class="login">Member Login</a>
                <?php else : ?>

                <a href="/account-page/" class="login">My Account</a>

                <?php endif; ?>
                <a href="/membership/join-sccap-renew-membership/"  class="join">Join</a>
0

The answer in your link is correct. If it's just showing PHP code then your code isn't between PHP tags <?php & ?>.

<?php if (!is_user_logged_in()) :?>
    <a href="/member-login/" class="login">Member Login</a>
<?php else : ?>
    <a href="/account-page/" class="login">Welcome <?php echo $current_user->display_name; ?></a>
<?php endif; ?>

<a href="/membership/join-sccap-renew-membership/"  class="join">Join</a>
  • 1
    it is also possible that you are not entering the code into a php template... – Michael Apr 9 '18 at 3:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.