1

I'm working on a theme that requires the end-user to specify the current performance season using a custom admin panel I've created, ie. "2013/2014", "2014/2015" etc., which I can retrieve using get_option('current_season');

On my custom nav menu I have a page titled "Season" that needs the aforementioned field inserted into it so it reads "2013/2014 Season" rather than just "Season".

The walker tutorials I have looked at only seem to show examples of adding a class to menu items but I need to add specific text to one menu item. How can I achieve this?

0

You can try the wp_nav_menu_objects filter. This seems to work, but not sure what other side-effects it may have, you'll want to test thoroughly.

function wpa_filter_nav_menu_objects( $items ){
    foreach( $items as $item ){
        if( 'Season' == $item->title ){
            $item->title = get_option('current_season') . ' Season';
        }
    }
    return $items;
}
add_filter( 'wp_nav_menu_objects', 'wpa_filter_nav_menu_objects' );
  • I'm astonished at what a knowledge of wordpress filters can do for a person. This worked brilliantly, right out of the box. I appreciate the assist and I'll let you know if I find any side-effects. – JMac Jun 9 '13 at 19:00
0

Most of individual menu item markup generation happens in Walker_Nav_Menu->start_el()

The title is going through filter in this part of code:

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

So the_title filter should allow you to modify it. However it is somewhat challenging to implement precisely and depends on your specifics how to target it, because WP uses same filter in get_the_title() function for titles in general.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.