Last active
November 1, 2022 02:42
-
-
Save levymetal/7dc5e1aa0a737ed1ba24 to your computer and use it in GitHub Desktop.
Return main menu if no sub menu items are found (http://christianvarga.com/how-to-get-submenu-items-from-a-wordpress-menu-based-on-parent-or-sibling/#comment-1710664829)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function my_wp_nav_menu( $theme_location = 'primary', $container = false, $items_wrap = "<div class='widget'><nav><ul>%3\$s</ul></nav></div>" ) { | |
$menu = wp_nav_menu(array( | |
'container' => $container, | |
'items_wrap' => $items_wrap, | |
'sub_menu' => true, | |
'theme_location' => $theme_location, | |
'echo' => false | |
)); | |
if ( $menu == '' ) { | |
$menu = wp_nav_menu(array( | |
'container' => $container, | |
'items_wrap' => $items_wrap, | |
'depth' => 1, | |
'theme_location' => $theme_location, | |
'echo' => false | |
)); | |
} | |
echo $menu; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment