Hi i was following a video and i keep getting errors even when using the wordpress devleopers docs

here is my code

      'top-menu' => 'Top Menu Location' ,
      'mobile-menu' => 'Mobile Menu Location' 

Thank you for taking the time to look and help!

  • Where did you add this code and how? did you manually add this code in functions.php or use a plugin, if you added the code manually, was it in a child theme? Oct 23, 2022 at 7:41
  • i added it in functions.php also im trying to develop on localhost
    – Ryfizzle
    Oct 23, 2022 at 8:05
  • Have you tried adding it inside of a callback of init or after_setup_theme? Oct 23, 2022 at 8:09
  • no i will try now
    – Ryfizzle
    Oct 23, 2022 at 8:38
  • 1
    Can you show a more complete example of your code, where are you adding it, what is before and after. Not everything that's inside functions.php but a few lines before and after your code, just to get an idea. Or you can pate the whole thing in a code sharing platform and paste the link, could be easier to find, just make sure to not share any sensitive information, like creds and keys Oct 23, 2022 at 9:02

1 Answer 1


In theme functions.php you just check this... I think it's may help you

In demo_menus function I use your code it works pretty well... I don't tell my code is good but I think this is best practice, we should try to best practice.

function demo_menus(){
    $locations = array(
        'top-menu' => __( 'Top Menu Location', 'text-domain' ),
        'mobile-menu' => __( 'Mobile Menu Location', 'text-domain' )
    register_nav_menus( $locations );
add_action( 'after_setup_theme', 'demo_menus' );

This is my localhost output


enter image description here

Your Answer

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

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