WordPress.org

Ready to get started?Download WordPress

Forums

Reverse Order of wp_nav_menu (14 posts)

  1. lightfoot33
    Member
    Posted 1 year ago #

    I have my navigation menu floating right which makes them appear in the reverse order that they should. I have searched the forum and thought I had my answer, which was to add this to my functions file:

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

    But they are still appearing in the opposite order that they should be. Can anyone help?

    Thank you.

  2. Peter_L
    Member
    Posted 1 year ago #

    Having your navigation float right does not make them appear in reverse order.

    You don't need the filter. Menus can be generated in different ways. Take a look at how the menu of your site is generated and look into how it functions.

  3. lightfoot33
    Member
    Posted 1 year ago #

    It actually is being dictated by the right float. If I remove it, the order is correct, but since it is set to float right (per the design) it appears it is in the opposite order. I would like to just use some PHP to tell it to reverse the order so the client doesn't have to remember to arrange it in the opposite order that they want it to appear.

  4. Peter_L
    Member
    Posted 1 year ago #

    Could you show the site?

  5. lightfoot33
    Member
    Posted 1 year ago #

    Unfortunately not yet, because it is still in a private pre-launch stage. But basically I can reiterate that the code is:

    • Item1
    • Item2
    • Item3

    and it shows up on the site as:
    Item3 | Item2 | Item1

    If I take out the float right, it works fine, but I need the navigation to anchor to the right side of the container, despite the # of navigation items... hence the float:right attribute on the li.

  6. lightfoot33
    Member
    Posted 1 year ago #

    Oops, the forum converted my code to actual html. Meant to say that the code is this:

    <ul>
    <li>Item1</li>
    <li>Item2</li>
    <li>Item3</li>
    </ul>

    and it shows up on the site as:
    Item3 | Item2 | Item1

  7. Peter_L
    Member
    Posted 1 year ago #

    It's starting to sound a bit like bad written css to me. So my advice is look into your css first before changing the wp template files.

  8. lightfoot33
    Member
    Posted 1 year ago #

    I have already taken a look at the CSS, which is how I know it's floating to the right. What other way can you make the navigation always anchor to the right side (despite the number of menu items) without using the float:right method?

    I know that this is the not the first time this issue has arisen with WordPress users, which is how I found the reverse order command for the functions.php file. My problem is that the command is not working for me, which is why I originally opened this thread.

  9. Peter_L
    Member
    Posted 1 year ago #

    Having your navigation float right does not make them appear in reverse order.

    You don't need the filter. Menus can be generated in different ways. Take a look at how the menu of your site is generated and look into how it functions.

  10. lightfoot33
    Member
    Posted 1 year ago #

    Removing the float:right does in fact reverse the order (back to the correct order). So I can confirm that to be true.

    To generate the menu, I am simply using:
    <?php wp_nav_menu(); ?>

  11. Peter_L
    Member
    Posted 1 year ago #

    Don't float the li's right, float the container ul right.

    You would need a filter to reverse the order of wp_nav_menu.

  12. lightfoot33
    Member
    Posted 1 year ago #

    I understand that. This is the filter I was trying to use but it didn't work:

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

    Thanks for you help. I think I will just figure out a different solution using CSS. I was just hoping to avoid reworking what was already there by using a filter, but at this point, it might be faster to find a different solution.

  13. Peter_L
    Member
    Posted 1 year ago #

    Have you tried wp_get_nav_menu_items
    http://codex.wordpress.org/Function_Reference/wp_get_nav_menu_items
    That seems to have an order ASC and DESC.

  14. lightfoot33
    Member
    Posted 1 year ago #

    I try that if I can't figure it a CSS solution.

Topic Closed

This topic has been closed to new replies.

About this Topic