Ok, this is a biggie. Here's the deal:
I have upwards of 50 installs of WordPress running on MAMP Pro locally. For some of them I use local/whatever, for others I set up virtual hosts as whatever.local/. WordPress has never had any problems. Yesterday, installed a copy of WP 3.0.1 (fresh, straight off the server), and started templating. Today, I returned to it to continue, first by registing default navigations. I put the necessary lines in functions.php:
add_theme_support( 'menus' );
add_action('init', 'register_custom_menu');
function register_custom_menus() {
register_nav_menu('primary_menu', __('Header Menu'));
register_nav_menu('404_menu', __('404 Menu'));
}
Fine, right? I also tried it with register_custom_menu, one at a time. In WordPress, no default menus show up. I've tried:
- Activate a different theme, re-activate the original
- Try Twenty Ten - still no custom navigations although a 'primary menu' is registered in the code, so it is NOT my functions.php
- Tried another theme that I have running locally (that works perfectly in its original place), still no navs
- Delete the entire database and re-install WP
- Delete the entire directory, re-download WP, re开发者_开发百科install
- Delete the virtual host and work from localhost/whatever
So, I have a ton of other WP sites working perfectly fine with nav registering, but I can't create any more? I'm completely, totally lost.
Any input would be appreciated, right now I'm at my wit's end. Let me know if you need any more information.
Three things:
- You should be hooking menu registration onto
'after_setup_theme'
, not'init'
- You don't need to call
add_theme_support()
sinceregister_nav_menu()
takes care of that. - You can use
register_nav_menus()
to take care of all your menus at once.
However, the biggest reason this isn't working is because you're not calling your function. The callback on add_action
should be 'register_custom_menus'
(notice plural). The spelling has to match the function declaration. This is how I'd suggest you rewrite it:
add_action('after_setup_theme', 'register_custom_menus');
function register_custom_menus() {
register_nav_menus( array(
'primary_menu' => __('Header Menu'),
'404_menu' => __('404 Menu') ) );
}
精彩评论