Support » Fixing WordPress » wp_nav_menu strtoupper

  • Resolved Jonathan

    (@jag1989)


    I’m wanting to create my menu system with only capital letters using the strtoupper() function. Within wp_nav_menu, the links are constructed with walk_nav_menu_tree, but cannot see how. I want to change the text that is displayed at the front end to be uppercase only.

    However if I change this:

    $items .= walk_nav_menu_tree( $sorted_menu_items, $args->depth, $args );
    to

    $items .= walk_nav_menu_tree( $sorted_menu_items, $args->depth, $args );
    $items = strtoupper($items);

    Everything within the UL LI is changed to uppercase, which I don’t want.

    Any help?

Viewing 3 replies - 1 through 3 (of 3 total)
  • For anyone else looking to do this, in nav-menu-template.php file, under the start_el() function you’ll find the line:

    $item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after;

    replace it with:

    $item_output .= $args->link_before . apply_filters( 'the_title', strtoupper($item->title), $item->ID ) . $args->link_after;

    Note the placement of strtoupper.

    Moderator keesiemeijer

    (@keesiemeijer)

    It’s better to create a custom walker for wp_nav_menu. That way you don’t have to hack core files:

    Put this custom walker with the changes that you want in your functions.php: http://pastebin.com/5ZmzWrgW

    And call wp_nav_menu with the callback to your custom walker like this:

    <?php wp_nav_menu( array( 'theme_location' => 'primary', 'walker' => new to_upper_walker())  ); ?>

    That’s great. Thanks.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘wp_nav_menu strtoupper’ is closed to new replies.