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>
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>
Share
Improve this question
asked Apr 9, 2018 at 1:51
SCCAP Web EditorSCCAP Web Editor
31 silver badge3 bronze badges
0
1 Answer
Reset to default 0The 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>
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745076414a4609862.html
评论列表(0条)