Maybe an odd question, I have a site that makes heavy use of nav menus. I'm looking to improve my site's performance, and since the menus hardly ever change, I wrote some PHP to spit them out into static files. What I can't figure out though, is if there is a way for me to hook into wp_nav_menu so that I can get the theme_location name (so that I can determine which static file to output) and then prevent wp_nav_menu from hitting the database and putting together the menu.

If I add in this filter:

add_filter('wp_nav_menu_args', 'my_wp_nav_menu_args_filter');
function my_wp_nav_menu_args_filter($args = array()) {
    //$args['walker'] = new my_walker_class();
    return array();//$args;

and then either return false or an empty array I still seem to get a nav, or an error generated in my custom walker. So is there no way to prevent a nav from being generated and from wp hitting the db trying to do it?


1 Answer 1


Once you supply a custom walker there is no need to return false or array(). Simply return $args and WP is going to delegate the menu generation to your custom walker.

  • Yes, but what I would like to do is to actually abort the nav process, and serve up a static version that I have saved on disk. I just can't seem to find a hook to abort, and then return some static html. Commented Jul 31, 2012 at 21:32
  • I think you can achieve that from within your walker and simply return the static html. Your walker doesn't have to follow the same rules as the default.
    – KalenGi
    Commented Aug 6, 2012 at 1:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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