I’ve looked and have not found anything that works.

I am trying to include a shortcode in a menu item’s ‘Navigation Label’. Basically Iwould like to have a dynamic title displaying the user’s name & avatar.

[profilepicture round] [user_name]

Right now it’s just spit back out since WordPress Menus do not parse shortcodes. I’ve tried:

function my_nav_menu_objects_shortcode_mangler($items) {
    foreach ($items as $item) {
       $item->title = do_shortcode($item->title);
    }
    return $items;
}

But it doesn’t parse it. I also tried $item->type_label with no luck. Am I just referencing the wrong attribute of item?

Also tried the following with no luck.

 add_filter('wp_nav_menu_items', 'do_shortcode');

The avatar and username can both be retrieved via php if needed:

<?php echo userpro_profile_data('user_login', $user_id); ?>
<?php echo userpro_profile_data('profilepicture', $user_id); ?>

2 s
2

First of all download ‘Shortcodes in Menus’ plugin and install/activate it.

Then in theme’s function.php add following code.

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

Now, in menu’s navigation lable write [current-username] shortcode.

Same thing you can do for displaying avatar.

This way it will display logged in user name in menu item.

Tags:

Leave a Reply

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