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'm not able to get nav menus to register - and I'm not sure what else to try when posted solutions are not working?

I've tried the solution in this post: register_nav_menus() won't register menus

And have also followed the instructions in: http://codex.wordpress.org/Function_Reference/register_nav_menus and http://wptuts.org/how-to-add-menu-to-wordpress-theme/

I cannot get this to work - I still get this message:

"The current theme does not natively support menus, but you can use the “Custom Menu” widget to add any menus you create here to the theme’s sidebar."

Currently in my functions.php file (keeping it simple - but isn't working):

register_nav_menu('primary_navigation', 'Primary Navigation');
add_action('after_setup_theme', 'hchw_setup');

This isn't working for me either (hchw is my theme name):

register_nav_menus(array(
    'primary_navigation' => __('Primary Navigation', 'hchw'),
    'sub_navigation' => __('Sub Navigation', 'hchw'),
));
add_action('after_setup_theme', 'hchw_setup');

My navigation template (header-top-navbar.php):

if (has_nav_menu('primary_navigation')) {
    wp_nav_menu(array('theme_location' => 'primary_navigation', 'menu_class' => 'nav'));
}

The include: <?php get_template_part('templates/header-top-navbar'); ?>

The entire functions.php file:

// Use 'static' instead of 'wp-content'
function rename_wp_content($path) {
  return str_replace('wp-content', 'static', $path);
}
add_filter('template_directory_uri', 'rename_wp_content');

// Is this an auth page?
function is_auth_page() {
  return in_array($GLOBALS['pagenow'], array('wp-login.php', 'wp-register.php'));
}

// Change login logo
function login_css() {
  wp_enqueue_style('login_css', get_template_directory_uri() . '/css/login.css');
}
add_action('login_head', 'login_css');

if (!defined('__DIR__')) { define('__DIR__', dirname(__FILE__)); }

require_once locate_template('/lib/utils.php');           // Utility functions
require_once locate_template('/lib/config.php');          // Configuration and constants
require_once locate_template('/lib/activation.php');      // Theme activation
require_once locate_template('/lib/cleanup.php');         // Cleanup
require_once locate_template('/lib/htaccess.php');        // Rewrites for assets, H5BP .htaccess
require_once locate_template('/lib/widgets.php');         // Sidebars and widgets
require_once locate_template('/lib/scripts.php');         // Scripts and stylesheets
require_once locate_template('/lib/post-types.php');      // Custom post types
require_once locate_template('/lib/metaboxes.php');       // Custom metaboxes
require_once locate_template('/lib/custom.php');          // Custom functions
//require_once locate_template('/lib/wp-admin-menu-classes.php'); // Load the Admin Menu Classes


/** 
* Load the Options Panel
**/
if ( !function_exists( 'optionsframework_init' ) ) {
    define( 'OPTIONS_FRAMEWORK_DIRECTORY', get_bloginfo('template_directory') . '/admin/' );
    require_once dirname( __FILE__ ) . '/admin/options-framework.php';
}

function hchw_setup() {

// Make theme available for translation
load_theme_textdomain('hchw', get_template_directory() . '/lang');

// Register wp_nav_menu() menus (http://codex.wordpress.org/Function_Reference/register_nav_menus)
//register_nav_menus(array(
//    'primary_navigation' => __('Primary Navigation', 'hchw'),
//    'sub_navigation' => __('Sub Navigation', 'hchw'),
//));


register_nav_menu('primary_navigation', 'Primary Navigation');
add_action('after_setup_theme', 'hchw_setup');


// Add post formats (http://codex.wordpress.org/Post_Formats)
// add_theme_support('post-formats', array('aside', 'gallery', 'link', 'image', 'quote', 'status', 'video', 'audio', 'chat'));

// Tell the TinyMCE editor to use a custom stylesheet
add_editor_style('assets/css/editor-style.css');

/**
 * Custom images size
**/  
// Add post thumbnails (http://codex.wordpress.org/Post_Thumbnails)
// This is then pulled through to your theme useing the_post_thumbnail('custombig'); 
add_theme_support('post-thumbnails');
  set_post_thumbnail_size(150, 150, false);
  add_image_size('category-thumb', 300, 9999); // 300px wide (and unlimited height)
  add_image_size('postfull', 504, 334); // Blog Post Full-Size
  add_image_size('customfeatins', 248, 165, true); //hp featured inset
  add_image_size('customfeatblg', 290, 192, true); //int featured inset
  add_image_size('customfeed', 136, 90, true); //feed thumbnails
  add_image_size('customparade', 176, 98, true); //logo parade

}

// Remove the link and 'Powered by WordPress' from the login page
function login_header_unlink() {
  return null;
}
add_filter('login_headerurl', 'login_header_unlink');
add_filter('login_headertitle', 'login_header_unlink');


/**
 * Add class to body tag if has sidebar
**/
function wpfme_has_sidebar($classes) {
    if (is_active_sidebar('sidebar')) {
        // add 'class-name' to the $classes array
        $classes[] = 'has_sidebar';
    }
    // return the $classes array
    return $classes;
}
add_filter('body_class','wpfme_has_sidebar');

Can anyone tell me what it is I'm missing, or if there is something incorrect with my code?

Thanks in advance for your any help or direction!

share|improve this question
    
Are you using a stand-alone Theme, or a child Theme? Where are you putting that code in functions.php? Just nakedly in the file, or properly wrapped in a callback and hooked into after_setup_theme? Where in your template file(s) are you calling wp_nav_menu()? Can you post that code as well? –  Chip Bennett Dec 6 '12 at 18:26
    
Hi Chip - This is a stand-alone theme. I'm putting this code nested with the rest of my functions, and before add_action('after_setup_theme', 'hchw_setup'); - I'm calling wp_nav_menu() in a template file... I will update my post with that code as well. –  ByteMyPixel Dec 6 '12 at 18:48
    
Can we see the entire "nested" code, so that we can see the register_nav_menus() call in context? –  Chip Bennett Dec 6 '12 at 19:09
    
I've updated my post with the functions.php code –  ByteMyPixel Dec 6 '12 at 19:14
    
I see - I had things nested incorrectly in my functions.php file - I found that the register_nav_menus() call should not be nested within the theme setup function (function hchw_setup()) Reading through this article on setting up theme functions helped me a bit as well: justintadlock.com/archives/2010/12/30/… –  ByteMyPixel Dec 6 '12 at 20:39

1 Answer 1

up vote 1 down vote accepted

In regard to this comment:

I see - I had things nested incorrectly in my functions.php file - I found that the register_nav_menus() call should not be nested within the theme setup function (function hchw_setup())

To the contrary, inside a callback hooked into after_setup_theme is exactly the right place for calls to register_nav_menus().

Your problem is a syntax error. You have placed your add_action() call inside the callback that it is attempting to hook, and as such, the callback never gets added to the hook:

function hchw_setup() {

// Make theme available for translation
load_theme_textdomain('hchw', get_template_directory() . '/lang');

// Register wp_nav_menu() menus (http://codex.wordpress.org/Function_Reference/register_nav_menus)
//register_nav_menus(array(
//    'primary_navigation' => __('Primary Navigation', 'hchw'),
//    'sub_navigation' => __('Sub Navigation', 'hchw'),
//));


register_nav_menu('primary_navigation', 'Primary Navigation');
add_action('after_setup_theme', 'hchw_setup');


// Add post formats (http://codex.wordpress.org/Post_Formats)
// add_theme_support('post-formats', array('aside', 'gallery', 'link', 'image', 'quote', 'status', 'video', 'audio', 'chat'));

// Tell the TinyMCE editor to use a custom stylesheet
add_editor_style('assets/css/editor-style.css');

/**
 * Custom images size
**/  
// Add post thumbnails (http://codex.wordpress.org/Post_Thumbnails)
// This is then pulled through to your theme useing the_post_thumbnail('custombig'); 
add_theme_support('post-thumbnails');
  set_post_thumbnail_size(150, 150, false);
  add_image_size('category-thumb', 300, 9999); // 300px wide (and unlimited height)
  add_image_size('postfull', 504, 334); // Blog Post Full-Size
  add_image_size('customfeatins', 248, 165, true); //hp featured inset
  add_image_size('customfeatblg', 290, 192, true); //int featured inset
  add_image_size('customfeed', 136, 90, true); //feed thumbnails
  add_image_size('customparade', 176, 98, true); //logo parade

}

Notice how this is inside the hchw_setup() function?

add_action('after_setup_theme', 'hchw_setup');

You need to move it outside the function:

function hchw_setup() {

// Make theme available for translation
load_theme_textdomain('hchw', get_template_directory() . '/lang');

// Register wp_nav_menu() menus (http://codex.wordpress.org/Function_Reference/register_nav_menus)
//register_nav_menus(array(
//    'primary_navigation' => __('Primary Navigation', 'hchw'),
//    'sub_navigation' => __('Sub Navigation', 'hchw'),
//));


register_nav_menu('primary_navigation', 'Primary Navigation');


// Add post formats (http://codex.wordpress.org/Post_Formats)
// add_theme_support('post-formats', array('aside', 'gallery', 'link', 'image', 'quote', 'status', 'video', 'audio', 'chat'));

// Tell the TinyMCE editor to use a custom stylesheet
add_editor_style('assets/css/editor-style.css');

/**
 * Custom images size
**/  
// Add post thumbnails (http://codex.wordpress.org/Post_Thumbnails)
// This is then pulled through to your theme useing the_post_thumbnail('custombig'); 
add_theme_support('post-thumbnails');
  set_post_thumbnail_size(150, 150, false);
  add_image_size('category-thumb', 300, 9999); // 300px wide (and unlimited height)
  add_image_size('postfull', 504, 334); // Blog Post Full-Size
  add_image_size('customfeatins', 248, 165, true); //hp featured inset
  add_image_size('customfeatblg', 290, 192, true); //int featured inset
  add_image_size('customfeed', 136, 90, true); //feed thumbnails
  add_image_size('customparade', 176, 98, true); //logo parade

}
// Move me outside the function
add_action('after_setup_theme', 'hchw_setup');
share|improve this answer
    
Hi Chip, That makes much more sense and fixed my issue! Thank you so much for clearing that up and explaining the correct syntax! –  ByteMyPixel Dec 6 '12 at 21:23

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.