Adding Custom Menu Locations in WordPress Themes

Basic Setup

Step 1: First, we need to register your new menus. In this example, we’ll create the menus Header Navigation and Expanded Footer. Add this PHP code to your functions.php, or link to it in a separate file:
[code]
// Add Your Menu Locations
function register_my_menus() {
register_nav_menus(
array(
‘header_navigation’ => __( ‘Header Navigation’ ),
‘expanded_footer’ => __( ‘Expanded Footer’ )
)
);
}
add_action( ‘init’, ‘register_my_menus’ );
[/code]

Step 2: Let your users know that your menu location exists by adding a message to the front end when no menu is yet assigned. Insert this code directly below the previous:
[code]
function default_header_nav() { // HTML markup for a default message in menu location
echo “


}

function default_expanded_footer() {
echo “


}
[/code]
Step 3: Insert this code into your templates wherever you want your Header Navigation menu to appear:
[code]
<?php
wp_nav_menu(array(
‘theme_location’ => ‘header_navigation’, // menu slug from step 1
‘container’ => false, // ‘div’ container will not be added
‘menu_class’ => ‘nav’, //

33 Replies to “Adding Custom Menu Locations in WordPress Themes”

  1. Hi, great staff.
    Little problem with “TEMPLATEPATH”…I am using a child theme, so it telling me that cannot find menus.php because it searching it inside of parent admin, not the child one.

    any idea?

  2. Hi there,
    Great tutorial. It helped me a lot to add custom menus in my website.
    But I am wondering about one thing, that is how can I add CSS to this custom menu?
    Thanks in advance for your professional support.

  3. Hi there, Great tutorial. It helped me a lot to add custom menus in my website. But I am wondering about one thing, that is how can I add CSS to this custom menu? Thanks in advance for your professional support.

Leave a Reply

Your email address will not be published. Required fields are marked *