Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question

2 Answers 2

up vote 0 down vote accepted

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' );
share|improve this answer
    
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

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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