admin管理员组文章数量:1022743
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 | Show 2 more comments1 Answer
Reset to default 1It 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.
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
1 Answer
Reset to default 1It 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.
本文标签: usershow to show logged in members username in wordpress content
版权声明:本文标题:users - how to show logged in members username in wordpress content 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745501520a2153413.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
<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