Username in nav

Hi, do you recommend a method for displaying a user’s username in the nav?

Previously, I’d added a shortcode to display this however it doesn’t seem to load properly after switching to Pro Headers

i was using the following method prior. In the child theme functions.php

add_shortcode( ‘current-username’ , ‘ss_get_current_username’ );
function ss_get_current_username(){
$user = wp_get_current_user();
return $user->display_name;
}

I would then display this as a nav label > [current-username]

any thoughts?

Hi @BelievePursue,

Thank you for reaching out to us. I tested your code in Pro and it works fine, to add the shortcode in Header Builder you can paste your shortcode in a Text element instead.

I noticed, there are pretty quotes in your code so this could be preventing your code to work, you can test the following code instead:

add_shortcode( "current-username" , "ss_get_current_username" );
function ss_get_current_username(){
	$user = wp_get_current_user();
	return $user->display_name;
}

Hope this helps!

I might be overlooking something obvious, if I’m trying to have the username appear as a nav element, how should I insert it as text instead?

I also updated to your code btw, while it didn’t solve it, it may at least be cleaner :slight_smile:

Hello @BelievePursue,

Please be advised that the navigation menu item label or title do not render a shortcode. This is why your shortcode is still displayed like a plain text.

You may need additional script so that it will be allowed. Regretfully this is beyond the scope of our support. May we recommend that you check out this link instead:

Hope this helps.

Thank you!

Your welcome!

Cheers.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.