I am creating a custom menu that shows the profile image and logged in user name of the user with the help of 'wp_nav_menu_items'.

Here, is the code that I am using to create the menu,

function my_custom_menu_item($items) {

        $dashboardUrl = site_url() . '/profile/';

        //Only incase the user is logged in, 
        //display the username and avatar.
        if (is_user_logged_in()) {
            $user = wp_get_current_user();

                $name = $user->display_name; // or user_login , user_firstname, user_lastname

                $avatar = get_avatar($current_user->user_email, 32);
                $items .= '<li><div class ="dash-menu"><a href="' . $dashboardUrl . '">' . $avatar . '<span class ="dash-username">' . $name . '</span></a></div></li>';
        return $items;

Now I want to create submenus for this above menu with profile image and name to my custom page links as a drop down in it. How can I do it?

I have gone through some links like:

How to add sub-menu to a menu generated by wp_nav_menu by using plugin

Add custom menu item using wp_nav_menu_items filter

But I am not able to figure it out. Can anyone please help?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.