roryashfordbentley/Wordpress-Bem-Menu

You need to first define a menu in WP-admin

sturobson opened this issue · 6 comments

This is, no doubt, an issue with my misunderstanding but...

I've pasted the relevant php into my functions.php and that seems to run smoothly.
I've set menu location in wp-admin > 'primary'.
I've added <?php bem_menu('primary', 'nav'); ?> into my header.php.

But I get - "You need to first define a menu in WP-admin" when I load up a page to see what happens.

Any ideas as to what I'm doing stupidly wrong?

Have you actually set values in the primary nav in the dashboard?

Assuming relevant php in functions.php means register_nav_menu('primary', 'Primary Menu') and you've created a menu in Dashboard, assigning it to that location…

bem_menu() is returning that error bc has_nav_menu('primary') is returning false (line 120), likely bc. that location hasn't been registered yet.

If you can show me how you've declared it in the functions. Also, your bem_menu function looks a little light. I usually do something like the following:

In the functions.php I have:

register_nav_menu('primary', 'Primary Nav');

And in the header.php I have:

wp_nav_menu( array( 'theme_location' => 'primary', 'menu_class' => '', 'menu' => 'primary', 'container' => '', 'items_wrap' => '%3$s' ) );

You don't need the 'items_wrap" method. That just takes the content out of a UL in an individual LI, so I can add the search to a final li element so it's all in a list.

What does the function bem_menu do?

seems, my theme needed me to add:
register_nav_menu('primary', 'Primary Nav');
... to functions.php and then set it in wp-admin. All working now. Thanks for all the replies 👍 ❤️

@tadywankenobi it gives BEM naming convention to WP navigation. So nice and tidy, imho.