Php Wordpress赢得';我们不允许注册菜单

Php Wordpress赢得';我们不允许注册菜单,php,wordpress,menu,Php,Wordpress,Menu,我第一次制作自己的自定义wordpress主题,在尝试注册菜单时遇到了一个障碍 我已经按照一个教程建立了主题,并查看了它,但无论我做什么,注册菜单的代码都不会工作,因为我在wp admin中没有看到要添加项目的菜单。 以下是我注册它们的函数: if ( ! function_exists( 'eastmids_setup' ) ): /** * Sets up theme defaults and registers support for various WordPress features

我第一次制作自己的自定义wordpress主题,在尝试注册菜单时遇到了一个障碍

我已经按照一个教程建立了主题,并查看了它,但无论我做什么,注册菜单的代码都不会工作,因为我在wp admin中没有看到要添加项目的菜单。 以下是我注册它们的函数:

if ( ! function_exists( 'eastmids_setup' ) ):
/**
 * Sets up theme defaults and registers support for various WordPress features.
 *
 * Note that this function is hooked into the after_setup_theme hook, which runs
 * before the init hook. The init hook is too late for some features, such as indicating
 * support post thumbnails.
 *
 * @since eastmids 1.0
 */
function eastmids_setup() {

/**
 * Custom template tags for this theme.
 */
require( get_template_directory() . '/inc/template-tags.php' );

/**
 * Custom functions that act independently of the theme templates
 */
require( get_template_directory() . '/inc/tweaks.php' );

/**
 * Make theme available for translation
 * Translations can be filed in the /languages/ directory
 * If you're building a theme based on eastmids, use a find and replace
 * to change 'eastmids' to the name of your theme in all the template files
 */
load_theme_textdomain( 'eastmids', get_template_directory() . '/languages' );

/**
 * Add default posts and comments RSS feed links to head
 */
add_theme_support( 'automatic-feed-links' );

/**
 * Enable support for the Aside Post Format
 */
add_theme_support( 'post-formats', array( 'aside' ) );

/**
 * This theme uses wp_nav_menu() in one location.
 */
register_nav_menus( array(
    'primary' => __( 'Primary Menu' ),
) );
}
endif; // eastmids_setup
add_action( 'after_setup_theme', 'eastmids_setup' );
下面是我如何使用它:

<nav role="navigation" class="site-navigation main-navigation">
     <?php wp_nav_menu( array( 'theme_location' => 'primary' ) ); ?>
</nav>

相反,显示的是一个ul标签,其中包含主页,后跟我的页面

鉴于我在wp admin中看不到菜单,我假设寄存器不知何故出现了故障


有人能帮忙吗?

这是因为您还没有指定菜单

设置菜单的代码后,应转到仪表板并从那里创建菜单(
外观
->
菜单
)。或者你也看不到这个菜单?有一个杂散的
endif在您的代码中,您可以发布完整的代码吗


输入菜单名,将所需项目添加到菜单中,然后单击创建菜单
。看看它是如何工作的。

啊,我明白了,我不知道“主要”名称是wp\u导航菜单呼叫位置的句柄。我的想法是,当我注册菜单时,它会显示为可在wp admin中添加项目的菜单,但当我去那里创建新菜单时,我在“主题位置”中找到了您的意思