WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?


share|improve this question

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.

share|improve this answer
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. – Scott Phillips Jul 31 '12 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 Aug 6 '12 at 1:31

Your Answer


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.