I have made a custom wordpress menu -
function my_custom_menu_item($items, $args)
{
if(is_user_logged_in() && $args->theme_location == 'primary')
{
$user=wp_get_current_user();
$name=$user->display_name;
$items .= '<li><a href="">'.$name.'</a></li>';
$items .= '<li><a href="/my-profile">My Profile</a></li>';
$items .= '<li><a href="/my-posts">My Posts</a></li>';
}
return $items;
}
add_filter( 'wp_nav_menu_items', 'my_custom_menu_item', 10, 2);
It shows 'name of the logged in user', 'My Profile', 'My Posts' side by side in a flat structutre.
I want 'My Profile' and 'My Posts' to show as dropdown under 'name of the logged in user'. How do I do that?
I have made a custom wordpress menu -
function my_custom_menu_item($items, $args)
{
if(is_user_logged_in() && $args->theme_location == 'primary')
{
$user=wp_get_current_user();
$name=$user->display_name;
$items .= '<li><a href="">'.$name.'</a></li>';
$items .= '<li><a href="/my-profile">My Profile</a></li>';
$items .= '<li><a href="/my-posts">My Posts</a></li>';
}
return $items;
}
add_filter( 'wp_nav_menu_items', 'my_custom_menu_item', 10, 2);
It shows 'name of the logged in user', 'My Profile', 'My Posts' side by side in a flat structutre.
I want 'My Profile' and 'My Posts' to show as dropdown under 'name of the logged in user'. How do I do that?
Share Improve this question asked Oct 2, 2019 at 17:10 Gissipi_453Gissipi_453 1053 bronze badges 01 Answer
Reset to default 1Remove the first closing </li>
and wrap the sub-items inside <ul></ul>
, then close the parent <li>
.
For Example:
function my_custom_menu_item($items, $args)
{
if(is_user_logged_in() && $args->theme_location == 'primary')
{
$user=wp_get_current_user();
$name=$user->display_name;
$items .= '<li><a href="">'.$name.'</a>';
$items .= '<ul>';
$items .= '<li><a href="/my-profile">My Profile</a></li>';
$items .= '<li><a href="/my-posts">My Posts</a></li>';
$items .= '<ul>';
$items .= '</li>';
}
return $items;
}
add_filter( 'wp_nav_menu_items', 'my_custom_menu_item', 10, 2);
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745111852a4611896.html
评论列表(0条)