WordPress version 3.0 has been live for a while and a lot of people want to make use of the wp_nav_menu() functionality but they are using one of the older template tags: wp_page_menu(); wp_list_pages(); or, wp_list_categories().

This post will be dealing with function arguments in common between wp_nav_menu() and wp_page_menu(). Follow-up posts will be covering wp_list_pages() and wp_list_categories(). I will not be covering the specific use for each function’s arguments; the idea is to help show how these options correlate to one another.

Let’s start with the full default of wp_nav_menu() 1 explicitly displayed:

wp_nav_menu( array(
    'menu'              => '',
    'container'         => 'div',
    'container_class'   => '',
    'container_id'      => '',
    'menu_class'        => 'menu',
    'menu_id'           => '',
    'echo'              => true,
    'fallback_cb'       => 'wp_page_menu',
    'before'            => '',
    'after'             => '',
    'link_before'       => '',
    'link_after'        => '',
    'depth'             => 0,
    'walker'            => '',
    'theme_location'    => ''
    ) );

Followed by the same explicit defaults of wp_page_menu() 2, 3:

wp_page_menu( array(
    'sort_column'       => 'menu_order, post_title',
    'include'           => '',
    'exclude'           => '',
    'show_home'         => false,    
    'menu_class'        => 'menu',
    'echo'              => true,
    'link_before'       => '',
    'link_after'        => ''
    ) );

Now onto updating wp_page_menu() to wp_nav_menu(), which turns out to be rather simple.

Here is the break-down of the wp_page_menu() default options from above:

  • 'sort_column' – not used
  • 'include' – not used
  • 'exclude' – not used
  • 'show_home' – not used (see bonus section below)
  • 'menu_class' – same as wp_nav_menu()
  • 'echo' – same as wp_nav_menu()
  • 'link_before' – same as wp_nav_menu()
  • 'link_after' – same as wp_nav_menu()

First off ‘sort_column’, ‘include’, and ‘exclude’ are replaced by the end-user’s choices using the UI of wp_nav_menu() found under Appearance | Menu in the dashboard. The balance of the default options are the same in wp_nav_menu(), with the exception of 'show_home' => false which is the “bonus” content.

Upgrading from wp_page_menu() to wp_nav_menu() may be as easy as a simple find and replace operation.

Bonus – Although the default in wp_page_menu() does not show a home page link you can add a custom menu item in wp_nav_menu() if you want one to appear. You may need to edit your theme to remove the orginal “home” link if one was being generated before upgrading.
NB: You may also need to add this line of code to your ‘functions.php’ template file to add custom menu support to your theme: add_theme_support( 'menus' );