首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >register_nav_menus()未注册

register_nav_menus()未注册
EN

WordPress Development用户
提问于 2023-05-17 04:48:53
回答 1查看 21关注 0票数 0

我正在学习udemy教程,我看不出哪里出了问题。菜单没有显示在WP管理员的菜单中。在本教程中,他们添加这段代码,然后单击customize>menus并将其与其他菜单列出(本教程使用wptest.io填写站点)。我有那些但没有“主菜单”。你能看到错误吗?接下来我该查什么?

style.css

代码语言:javascript
复制
 /*
Theme Name: My Sandbox Theme
Author: me
Author URI: https://me.com
Description: This my sandbox site 
Version: 1
License: GNU General Public License v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Text Domain: mysandbox
Tags: blog, one-column, custom-background, custom-colors, custom-logo, custom-menu, editor-style, featured-images, footer-widgets, full-width-template, rtl-language-support, sticky-post, theme-options, threaded-comments, translation-ready, block-styles, wide-blocks, accessibility-ready

Maecenas mi ipsum, blandit ac diam eget, tincidunt auctor augue. Sed maximus elit quam, eget fermentum leo dignissim id. Aliquam molestie lectus et tortor sodales, vitae accumsan nibh placerat. Fusce ultricies congue felis in facilisis. Suspendisse porttitor dictum eros, sit amet hendrerit velit l
*/

functions.php

代码语言:javascript
复制
<?php
// Add theme support
add_theme_support( 'title-tag');
add_theme_support( 'post-thumbnails' );
add_theme_support( 'post-format', ['aside', 'gallery', 'link', 'image', 'quote', 'status', 'video', 'audio', 'chat']);
add_theme_support( 'html5' );
add_theme_support( 'automatic-feed_lnks' );
add_theme_support( 'custom-background' );
add_theme_support( 'custom-header' );
add_theme_support( 'custome-logo' );
add_theme_support( 'customize-selective-refresh-widgets' );
add_theme_support( 'starter-content' );

// Load in our CSS
function wphierarchy_enqueue_styles(){
    
    wp_enqueue_style( 'main-css', get_stylesheet_directory_uri() . '/style.css', [], time(), 'all' );

}
add_action( 'wp_enqueue_scripts', 'wphierarchy_enqueue_styles' );




//Register Menu Locations

register_nav_menus([
    'main-menu' => esc_html__('Main Menu', 'myfirsttheme'),
])
?>

index.php

代码语言:javascript
复制
<?php get_header(); ?>

<h1>Index.php</h1>

<?php get_footer(); ?

header.php

代码语言:javascript
复制
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <?php wp_head(); ?>
</head>

<body <?php body_class(); ?>>

footer.php

代码语言:javascript
复制
My Footer <?php echo date('Y'); ?>

<?php wp_footer(); ?>

</body>

</html>
EN

回答 1

WordPress Development用户

发布于 2023-05-17 05:20:24

也许事情发生得太早了,以后再被踩到。尝试使用传统的方法,在init钩子回调中这样做,如下所示:

代码语言:javascript
复制
function register_my_menu() {
    register_nav_menus([
        'main-menu' => esc_html__('Main Menu', 'myfirsttheme'),
    ]);
}
add_action( 'init', 'register_my_menu' );
票数 1
EN
页面原文内容由WordPress Development提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://wordpress.stackexchange.com/questions/416096

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档