Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress How to Make a Website with WordPress WordPress Widgets and Custom Menus How to Add Custom Menus to a WordPress Theme

Rebecca Jensen
Rebecca Jensen
11,580 Points

Menu not appearing

I've been working on creating a custom post type, using content-detail.php to generate the posts and detail.php to house all the posts.

I wanted to create a custom menu for detail.php, so I pasted this code into functions.php:

function register_my_menus() {
  register_nav_menus(
    array(
      'detail-menu' => __( 'Details Menu' )      
    )
  );
}
add_action( 'init', 'register_my_menus' );

And I pasted this into detail.php:

<?php wp_nav_menu( array('menu' ==> 'Details Menu' )); ?>

I've also gone into Appearance > Menus and created a menu called "Details" and added several of the "details" posts to the menu. I've saved it. I've tried it with and without the checkbox to Theme Locations, Details Menu, checked. When I look in Manage Locations, the Theme Location "Details Menu" is set to the Assigned Menu, "Details."

Not sure where I'm going wrong.

I also have this ABOVE my register_my_menus code in functions.php:

add_theme_support( 'menus' );

function register_theme_menus() {
    register_nav_menus(
        array(
            'header-menu' => __( 'Header Menu' )
            )
    );
}
add_action( 'init', 'register_theme_menus' );

1 Answer

Hi Rebecca,

Can you try changing:

<?php wp_nav_menu( array('menu' ==> 'Details Menu' )); ?>

to:

<?php wp_nav_menu( array('theme_location' => 'detail-menu' )); ?>

Does that make any difference?

EDIT: It's probably something incredibly obvious but I just can't spot what's wrong. It looks like you're already doing it but, to make it easier, this is what I'm currently using in my latest build.

At the top of functions.php I have:

    add_theme_support( 'menus' );

Just under that (still in functions.php I have):

    function new_register_theme_menus(){
        register_nav_menus(
            array(
                'main-menu' => __( 'Main Menu' ),
                'sub-menu' => __( 'Sub Menu' )
            )
        );
    }
    add_action( 'init', 'new_register_theme_menus' );

Finally, in my case, I've added the following to header.php:

<?php

    $defaults = array(
        'theme_location' => 'main-menu',
        'menu_class' => 'custom-style-here',
        );

    wp_nav_menu( $defaults );

?>

Hopefully that helps in some way :)

-Rich

Hi Rebecca,

Removed my original answer and updated it with a new one to avoid confusion. Can you try that please?

-Rich

Just made one other change...sorry!

-Rich

Rebecca Jensen
Rebecca Jensen
11,580 Points

Hmm, I tried

<?php wp_nav_menu( array('theme_location' => 'detail-menu' )); ?>

in my detail.php file, but nothing changed.

Hi Rebecca,

Realised you may not have received the notification but updated my answer with what I have working.

-Rich

Rebecca Jensen
Rebecca Jensen
11,580 Points

Yes, your code works! Thank you!

No problem :)