php - Displaying logged in user name

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 ad

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
Add a comment  | 

1 Answer 1

Reset to default 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>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745076414a4609862.html

相关推荐

  • php - Displaying logged in user name

    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 ad

    19小时前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信