users - how to show logged in members username in wordpress content

I'm working on a page on a site but got stuck at this point I want to show the logged in members usernamefirst nam

I'm working on a page on a site but got stuck at this point I want to show the logged in members username/first name of the site content for that I'm using this code

<?php if ( is_user_logged_in() ) { ?>
    <!-- text that logged in users will see -->
<?php global $current_user; get_currentuserinfo(); ?>
<h5>Hi <?php echo $current_user->user_firstname; ?></h5>
<p>You have access to all of the free members stuff, enjoy :) <a href=".php?action=logout"> Logout </a></p>
<?php } ?>

but instead of showing the username i shows broken code like this See Screenshot. I'm creating the page with WPBakery.

I'm working on a page on a site but got stuck at this point I want to show the logged in members username/first name of the site content for that I'm using this code

<?php if ( is_user_logged_in() ) { ?>
    <!-- text that logged in users will see -->
<?php global $current_user; get_currentuserinfo(); ?>
<h5>Hi <?php echo $current_user->user_firstname; ?></h5>
<p>You have access to all of the free members stuff, enjoy :) <a href="http://example/wp-login.php?action=logout"> Logout </a></p>
<?php } ?>

but instead of showing the username i shows broken code like this See Screenshot. I'm creating the page with WPBakery.

Share Improve this question edited May 11, 2019 at 18:30 fuxia 107k39 gold badges255 silver badges459 bronze badges asked May 11, 2019 at 16:12 Yasir RehmanYasir Rehman 12 bronze badges 7
  • @fuxia that answer didn't work for me – Yasir Rehman Commented May 12, 2019 at 10:30
  • What happens when you replace <h5>Hi <?php echo $current_user->user_firstname; ?></h5> with <h5>Hi <?php echo $current_user->display_name; ?></h5> or with <h5>Hi <?php echo "Foobar"; ?></h5>? Still weird output? Then something else in your code somewhere else is broken. – norman.lol Commented May 12, 2019 at 11:27
  • i see this i.imgur/JwPooHw.png – Yasir Rehman Commented May 12, 2019 at 11:28
  • Yes, I got that. It's the same screenshot as in your question. But what happens when you replace it with the code I suggested? – norman.lol Commented May 12, 2019 at 11:30
  • nothing changes – Yasir Rehman Commented May 12, 2019 at 11:30
 |  Show 2 more comments

1 Answer 1

Reset to default 1

It looks like $current_user->user_firstname contains some tag content.

I would replace that line with:

<h5>Hi <?php echo esc_html($current_user->user_firstname); ?></h5>

or

<h5>Hi <?php echo strip_tags($current_user->user_firstname); ?></h5>

One of those (or either) may solve your problem outright.

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

相关推荐

  • users - how to show logged in members username in wordpress content

    I'm working on a page on a site but got stuck at this point I want to show the logged in members usernamefirst nam

    3小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

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

关注微信