最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - Displaying logged in user name

programmeradmin2浏览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>

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>

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论