Show user name instead of Profile.

4.54K viewsCore
0

Is it possible that instead of Profile link in the menu it should show Username or just Name? if its possible please tell how it can be implemented

edited answer
1

add this to your function.php:

add_filter(‘wp_nav_menu_items’,’my_login_func’, 10, 2);

function my_login_func($nav, $args) {
ob_start();
wp_loginout(‘index.php’);
$loginoutlink = ob_get_contents();
ob_end_clean();

//change primary to secondary if u use secondary menu
if( $args->theme_location == ‘primary-menu’ ) {
if(is_user_logged_in())
{
$user=wp_get_current_user();
$name=$user->display_name; // or user_login , user_firstname, user_lastname
$nav .= ‘<li><a href=”YOURLINK”>| Hi, ‘.$name.’ |</a></li>’;
$nav .= ‘<li>’. $loginoutlink .'</li>’;
}
else {
$nav .= ‘<li><a href=”YOURLINK”>| Login/Register |</a></li>’;
}
}
return $nav;

edited answer
You are viewing 1 out of 1 answers, click here to view all answers.