Jubayer Hossain

How To Get Username In WordPress Using PHP

To get the current username in wordpress using php you have write this custom code in functions.php

				
					function getUser(){
	 $current_user = wp_get_current_user();
	$userName = $current_user->display_name;
	?>
	<span><i class="fas fa-user"></i>  <?php echo $userName ?></span>
<?php }
add_shortcode("username","getUser");
				
			
And then you can user this shortcode [username] anywhere that you want to output the user name.

2 thoughts on “How To Get Username In WordPress Using PHP”

  1. You’re in point of fact a just right webmaster.
    The web site loading velocity is amazing. It seems that you are doing any unique
    trick. Furthermore, the contents are masterwork.
    you’ve performed a wonderful task on this topic! Similar here:

  2. Hi there, just became alert to your blog through Google,
    and found that it is really informative. I’m gonna watch
    out for brussels. I will be grateful if you continue this
    in future. A lot of people will be benefited from your writing.
    Cheers!

Leave a Comment

Your email address will not be published. Required fields are marked *