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.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745501522a4630437.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