Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I've read a few tutorials on how to add the functionality of the custom menus added in version 3.0 to my theme but they all seem to differ somewhat, and I'm not sure whether they contain superfluous code. In addition I read that the code to register your theme as menu-compatible changed between the RC and the public release.

What's the simplest way of adding support for custom menus to my theme?

share|improve this question

3 Answers 3

up vote 7 down vote accepted

The easiest way is to use the register_nav_menus function.This should be hooked into 'after_setup_theme':

function my_cool_menu_function(){
  register_nav_menus( array(
    'primary' => 'Primary Navigation'
  ));
}

add_action( 'after_setup_theme', 'my_cool_menu_function' );

Then, in your theme, simply call that menu's position:

wp_nav_menu( array( 'theme_location' => 'primary' ) );
share|improve this answer

This how to include the custom navigation in its simplest form, I believe it picks up the navigation with not identifier:

<div class="access">
  <?php wp_nav_menu(); ?>
</div>

There are also basic options that can be passed to the function, here's what I generally use:

$navArgs=array(
    'menu_id' => 'nav',    // target the nav menu
    'container' => '',     // don't wrap the menu in <ul>
);
share|improve this answer

Add this to functions.php of your theme. If you don't have one, create it.:

<?php
add_theme_support('menus');
function register_my_menus() {
    $args = array( 
        'menu-1' => __( 'Main Menu' )
    );
    register_nav_menus( $args );
}
add_action( 'init', 'register_my_menus' );
?>

And this can go anywhere, I have it in header.php (see wp_nav_menu() docs):

<?php
$args = array(
    'menu' => 'Main Menu',
    'sort_column' => 'menu_order',
    'container' => 'div',
);
wp_nav_menu( $args ); ?>
share|improve this answer

Your Answer

 
discard

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.