2018-06-07 21:39
浏览 46


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:


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() {
      '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.

图片转代码服务由CSDN问答提供 功能建议

我是一名WordPress初学者,在我使用MAMP设置的本地服务器上工作。 我创建了样式,索引,页脚,标题和函数文档,PHP组装了所有内容,没有任何问题。 该网站按预期发布了我的所有文件。 然后我尝试将自定义菜单添加到管理仪表板中的外观面板/菜单,但它们不会显示。



< / a>


 \  nfunction macsc_script_enqueue(){
 wp_enqueue_style('customstyle',get_template_directory_uri()。'/ css / macc.css',array(),'1.0.0','all'); 
 wp_enqueue_script('customjs',get_template_directory_uri  ()。'/ js / macsc.js',array(),'1.0.0',true); 
function register_my_menus(){  
'header-menu'=&gt; __('标题菜单'),
'extra-menu'=&gt; __('Extra Menu')

我已阅读了几个堆栈溢出线程,并查阅了WordPress Codex支持文档。 register_my_menus函数是WordPress doc的直接复制和粘贴。 据我所知,我正在做的一切正确(当然,显然不是这样)。

对我来说,有一件事似乎很奇怪,那就是“小部件”已经有了标签。 “外观”面板中的“菜单”和“标题”。 考虑到这是一个以空文件夹开头的自定义主题,我不知道为什么会有这些主题。


  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dongxianrang9269 2018-06-07 21: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.

    解决 无用
    打赏 举报

相关推荐 更多相似问题