John Davidson

php - wp_nav_menu() showing list in a different Position?


While trying to add menu list as the following

<div class="dropdown-menu" aria-labelledby="navbarDropdown">

'theme_location' => 'header_menu_location',
'echo' => false,
'items_wrap' => '%3$s'




This function should show list items within div element but what I get is that it is being shown right after the outer li element. What's even weird about it is that when I do not use attribute 'items_wrap' the output is showing properly inside of the div container, only when I add this attribute to the args array ـــ the output list appears outside of its div container.
What am I doing wrong?

My Answer:
To change the position of the menu list in WordPress using the `wp_nav_menu()` function, you can use the `menu_class` parameter to add a custom class to the menu list and then use CSS to position it as needed.

Here's an example of how you can do this:

1. Add the `menu_class` parameter to the `wp_nav_menu()` function in your theme file where you want to display the menu list. For example:

wp_nav_menu( array(
'theme_location' => 'primary',
'menu_class' => 'custom-menu-class'
) );

2. Add custom CSS to your theme's stylesheet to position the menu list. For example, you can use the following CSS code to position the menu list to the right:

.custom-menu-class {
float: right;

You can adjust the CSS properties as needed to position the menu list in the desired location on your website.

Remember to clear your browser cache after making these changes to see the updated position of the menu list.

Rate this post

3 of 5 based on 8570 votes


© 2024 - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us