WordPress cache a menu with Transient API

wp_nav_menu() doesn’t return anything by default, it just echoes out formatted html.

For wp_nav_menu() to return a value you will need to pass 'echo' => false into it’s arguments, like so:

$housemenu = wp_nav_menu( array(
    'menu' => '',
    'menu_class' => 'sf-menu',
    'menu_id' => 'nav',
    'walker' => new description_walker(),
    'echo' => 'false'
));

It should be noted that by caching the entire menu in a transient, you will lose it dynamic nature. For instance if it cached it while on your home page all of the active classes applied to the menu items will ALWAYS reflect the home page. Thus if you were to visit a different page the active classes on the menu items would be wrong.

This will cause quite a bit of pain if you wish to convey via CSS which page the current user is on.

tech