Upgrade wp_page_menu() to wp_nav_menu()
in Functions
as how-to, WordPress, wp_nav_menu, wp_page_menu
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.
add_theme_support( 'menus' );





