Support » Fixing WordPress » wp_nav_menu sort order?

  • Hey Guys,
    I’m trying to build a right aligned, wrapping capable wp_nav powered menu.

    Is there a way to have it rendered backwards, so that float: right; would work and not mess up the order?

    I was hoping for something like this:

    <?php wp_nav_menu( array('sort_order' => 'DESC' )); ?>


Viewing 10 replies - 1 through 10 (of 10 total)
  • Bump?



    Forum Moderator

    There’s no sort_order attribute for wp_nav_menu:

    I understand that, I was hoping there was another way to do it. Perhaps a filter of some sort?



    Forum Moderator

    Not that I know of. Also, it wouldn’t make any sense to have a sort order since the whole point behind wp_nav_menu is that site owners can set up their own custom menu with their preferred order. Are you perhaps looking for a sort order for the default fallback, wp_page_menu? That has a sort_column attribute but not an order one.

    It makes complete sense to need to return the values in the reverse of the order the user intended. For instance, I have a main nav where each item floats left, but a footer nav where they float right. The menu appears backwards down in the footer since the first item gets pushed to the far right.

    It would be great to be able to reverse the order the elements are spit out.

    I have the same issue. I think being able to reverse the order make good sense as well. I’ll post a solution if I find one.

    Well this works, but it seems inefficient:

    add_filter('wp_nav_menu_objects', create_function('$menu', 'return array_reverse(array_reverse($menu ));'));

    I used array_reverse twice to get the order the way I wanted. It works using it only once for the opposite order:

    add_filter('wp_nav_menu_objects', create_function('$menu', 'return array_reverse($menu );'));

    Put in your theme’s functions.php

    Is there any way to filter it for just one menu?

    Using this function might be a better method, especially for targeting just one menu:

    Best bet is to rework the HTML and CSS so that you can avoid floating the menu items right. Maybe you could float the menu’s container right, then float the list items left within that container.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘wp_nav_menu sort order?’ is closed to new replies.