0
votes

I'm struggling with an issue registering my custom menu in WP. I have read all the text and various forums about custom menus in wp, but cannot seem to figure out how to get mine to work.

Here is the code snippet I am adding to my function.php file:

function register_my_menu() {
  register_nav_menu('header-menu',__( 'Header Menu' ));
}
add_action( 'init', 'register_my_menu' );

and then adding this bit of code to the header.php file where I want the menu to be:

<?php wp_nav_menu( array( 'theme-location' => 'header-menu' ) ); ?>

Both snippets taken directly from: https://wordpress.org/support/topic/register_nav_menu-not-actually-registering-menus

Now I have tried entering these codes differently, in different orders, renaming them, to no avail. Nothing seems to work. When I view my WP site, I find the top part of the side has the functions.php code showing at the top and the option to edit the menu in the admin panel never appears.

Here is even a screen shot of the result i get when I use this code. http://i.stack.imgur.com/5XiEu.jpg

Is there something I'm doing wrong???

IF so, how can I fix it?

I would be much obliged to get some assistance, as I am very new to WP.

1
put <?php and ?> tag in functions.php file - Tamil Selvan C
Thanks for responding so quick, however this only created an error. Instead of loading the page, this was shown at the top of the screen: Parse error: syntax error, unexpected '' (T_STRING) in /homepages/24/d538682299/htdocs/clickandbuilds/DixieAccidentChiropractor/wp-content/themes/chiropractor/functions.php on line 3. Any suggestions on what I may have done wrong? I added the opening tags and closing php tags. Here is exactly what I entered: <?php function register_my_menu() { register_nav_menu('header-menu''Header Menu' )); } add_action( 'init', 'register_my_menu' ); ?> - Brittney Hillerich
You're missing a comma in 'header-menu''Header Menu' - doublesharp
Download Sublime Text 3, open your functions.php file and look at that code you put, and then if the code inside is colored differently then the code that usually works, then your php tags are either missing, or you have unnecessary php tags. Post that part of the code (with few lines about and below so that we can see if you've put your code well). - dingo_d
doublesharp: That is just the error message that I get when the WP page loads. The above code stated in my first posting is the actual code that is in the function.php file. I'm not sure why the error leaves out a comma, as all comma's are in place in the actual code. - Brittney Hillerich

1 Answers

0
votes

Thanks for the responses, I finally figured it out!

At first I had not php tags.

Then I was adding an opening and then a closing tag: <?php and ?> at the end.

I picked apart the twenty-thirteen theme and then copied my code over to it.

I then realized, that the function.php file only needed the opening tag "<?php...and now all is good!

So my final code was:

<?php
    function register_my_menu() {
      register_nav_menu('header-menu',__( 'Header Menu' ));
    }
    add_action( 'init', 'register_my_menu' );

Worked like a charm!