我正在学习udemy教程,我看不出哪里出了问题。菜单没有显示在WP管理员的菜单中。在本教程中,他们添加这段代码,然后单击customize>menus并将其与其他菜单列出(本教程使用wptest.io填写站点)。我有那些但没有“主菜单”。你能看到错误吗?接下来我该查什么?
style.css
/*
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
<?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
<?php get_header(); ?>
<h1>Index.php</h1>
<?php get_footer(); ?header.php
<!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
My Footer <?php echo date('Y'); ?>
<?php wp_footer(); ?>
</body>
</html>发布于 2023-05-17 05:20:24
也许事情发生得太早了,以后再被踩到。尝试使用传统的方法,在init钩子回调中这样做,如下所示:
function register_my_menu() {
register_nav_menus([
'main-menu' => esc_html__('Main Menu', 'myfirsttheme'),
]);
}
add_action( 'init', 'register_my_menu' );https://wordpress.stackexchange.com/questions/416096
复制相似问题