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.

So, I have a news website. The designers want me to have a link in the menu that says "Latest News - [time of the last post]".

I know I can get the datetime of the latest post with get_lastpostdate().

But how can I put this php code inside the menu? This specific link is not the first one nor the last. It's inside the menu structure. Menus in this website are made trough the usual custom menu tools of wp.

Any ideas?

share|improve this question
    
Using Navigation Walker class you can customize menu items in WP menu. Check this –  Nilambar Jul 4 at 9:15
    
What should I look for? Ok, extend the walker class. But how can I access from inside the walker one specific menu item and add code to it? Wouldn't a filter be better? Because I really have to do this just once. –  Alevalentini Jul 4 at 9:32
    
Yes, you can also use filter. Filter wp_get_nav_menu_items is available. args parameter is passed in both Walker class and filter also. Both method is applicable and you can choose any one. In filter three parameters are passed. return apply_filters( 'wp_get_nav_menu_items', $items, $menu, $args ); –  Nilambar Jul 4 at 9:53
    
Should I use $item to pass the name of the menu link? –  Alevalentini Jul 4 at 10:20

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.