Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Reverse wordpress nav menu
/**
* Enables a 'reverse' option for wp_nav_menu to reverse the order of menu
* items. Usage:
*
* wp_nav_menu(array('reverse' => TRUE, ...));
*/
function my_reverse_nav_menu($menu, $args) {
if (isset($args->reverse) && $args->reverse) {
return array_reverse($menu);
}
return $menu;
}
add_filter('wp_nav_menu_objects', 'my_reverse_nav_menu', 10, 2);
@eliements

This comment has been minimized.

Copy link

@eliements eliements commented Aug 6, 2014

Thanks for sharing this!
I just have one question: Is there a way to only affect the reverse order of the main menu and not the submenus?

@timnovinger

This comment has been minimized.

Copy link

@timnovinger timnovinger commented Apr 10, 2017

@eliements You can do that by add_filter() right before you invoke wp_nav_menu() for the main menu and then remove_filter() immediately thereafter. Then it won't affect other menus.

@upss1988

This comment has been minimized.

Copy link

@upss1988 upss1988 commented Aug 5, 2018

Thanks man. Awesome solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.