When I was creating a WordPress theme for my client I needed to get dropdown of Navigation menus in customize so user can choose a menu. I wrote a function for that which really worked well. You can use it if you need it. Add it these below codes in your themes function.php file. It creates the dropdown. /** * Dropdown Menu List for customizer */ if ( !function_exists( 'your_theme_customizer_menulist' ) ) { // Function function your_theme_customizer_menulist() { $menus = wp_get_nav_menus(); $menu_list['none'] = esc_html__(' — Choose Menu — ', 'your-theme'); foreach ($menus as $menu) { $menu_list[$menu->slug] = $menu->name; } return $menu_list; } } Explanation of the above code: Set a variable $menu to get all available menus, then set an another variable $menu_list to store the dropdown value. Now do a foreach loop to exact the menus into drowdown options. Add the below code in function.php to create setting in… read more
Very nice post. well defined. Thanks for sharing the information.