0

I'm following an udemy tutorial and can't see where I'm going wrong. The menu is not showing up in WP admin's Menus. In the tutorial, they add this code, then click customize>menus and it's listed with the other menus (the tutorial used wptest.io to fill out the site). I have those but not 'Main menu'. Can you see an error? What should I check next?

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>

1 Answer 1

1

Perhaps it's happening too early and getting stomped on later. Try doing it the traditional way, in an init hook callback, like so:

function register_my_menu() {
    register_nav_menus([
        'main-menu' => esc_html__('Main Menu', 'myfirsttheme'),
    ]);
}
add_action( 'init', 'register_my_menu' );
5
  • Tried that with the same result. :/ Just nothing added to the customizing>Menus.
    – Fio
    May 17 at 7:21
  • Is it possible that you are confusing menu locations with actual menus? register_nav_menu creates a new place to PUT a menu, not an actual menu. You have to select a menu in customization (or add a new one,) then scroll down to see the choices of where it should show up. You should see main menu down there
    – Brian Page
    May 17 at 7:26
  • So I would have to manually create the menu in the admin, then that's what I can access with this code? That was skipped in the tut. I was under the impression this code created the menu item.
    – Fio
    May 17 at 7:35
  • Right. This is just for putting a menu in a new place, like the footer, or whatever. So then a template can include or not. Well, except that you can set a menu to automatically include all new pages, so it's not quite 'manually'
    – Brian Page
    May 17 at 7:41
  • Ok awesome. That explains why nothing was appearing. Thanks, for the help!
    – Fio
    May 17 at 8:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.