dongtang2376 2018-06-07 13:39
浏览 46
已采纳

自定义菜单未显示在WordPress的“菜单设置”中

I'm a WordPress beginner working on a local server I set up with MAMP. I created the style, index, footer, header and functions docs, and PHP assembled everything with no problems. The website published all my files as expected. Then I tried to add custom menus to the appearance panel / menus in the admin dashboard, but they wouldn't show up.

Here's a snapshot of my folder hierarchy:

shot of folder hierarchy

And here's a screenshot of the admin page:

enter image description here

And this is all the code in my functions.php file so far:

<?php

function macsc_script_enqueue() {
    wp_enqueue_style('customstyle', get_template_directory_uri() . '/css/macsc.css', array(), '1.0.0', 'all');
    wp_enqueue_script('customjs', get_template_directory_uri() . '/js/macsc.js', array(), '1.0.0', true);
}

add_action('wp_enqueue_scripts', 'macsc_script_enqueue');

function register_my_menus() {
  register_nav_menus(
    array(
      'header-menu' => __( 'Header Menu' ),
      'extra-menu' => __( 'Extra Menu' )
    )
  );
}
add_action( 'init', 'register_my_menus' );

I've read several stack overflow threads and consulted the WordPress Codex support documentation. The register_my_menus function was a direct copy and paste from the WordPress doc. As far as I can tell, I'm doing everything correctly (obviously not, of course).

One thing that seems odd to me is that there were already tabs for "widgets," "menus" and "header" in the Appearance panel. Considering this is a custom theme that started with an empty folder, I'm not sure why those are there at all.

Any help would be greatly appreciated.

展开全部

  • 写回答

2条回答 默认 最新

  • dongxianrang9269 2018-06-07 13:49
    关注

    Typically menus are registered on the after_setup_theme hook. I'd try using that instead of init.

    Also you don't need to register custom widgets or widget area support for the Widgets menu to show up, there's a lot that WordPress introduces in the core, regardless of your theme or active plugins.

    And on second glance, it appears the TwentySeventeen theme is active, considering the Top Menu and Social Links Menu are the default menus in the TwentySeventeen (default) theme.

    From TwentySeventeen/functions.php:

    register_nav_menus( array(
        'top'    => __( 'Top Menu', 'twentyseventeen' ),
        'social' => __( 'Social Links Menu', 'twentyseventeen' ),
    ) );
    

    Go to Appearance > Themes and make sure your custom theme is activated.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?

悬赏问题

  • ¥15 方波信号时频特征分析/信号调制与解调过程分析/利用DFT分析信号频谱
  • ¥20 两台硬件相同的琴设备一个是高阶版,怎么扒到初阶版
  • ¥30 matlab求解周期与坐标
  • ¥15 MATLAB图片转灰度格式问题
  • ¥15 把h5作品链接复制到自己的账号里
  • ¥15 ensp抓包实验配置
  • ¥15 强化学习算法、MRO
  • ¥15 想要学习一门技术来保证以后能够吃上碗饭,该学什么好
  • ¥100 对这段代码用Astro进行layout,用redhawk进行ir drop 的测试和分析,以及降低ir drop 的方法和实现
  • ¥20 matlab绘冲床平面连杆机构图和仿真,求帮助
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部