• Skip to primary navigation
  • Skip to main content
OsomCode

OsomCode

Awesome code tutorials for WordPress and Genesis

  • Subscribe
  • My account
    • Edit profile
    • Favorites
    • Update credit card
  • Login

Get a list of all menu locations in a WordPress theme

Find out in this tutorial how to get a list of all menu locations registered by a WordPress theme using code.

Depending on the theme you have installed you will have different menu areas or locations registered (header, footer…). Therefore, if you want to modify only the menu that is in a certain location you will need to know what it is called.

Therefore, in this tutorial you are going to see how to get a list of all the menu locations that a theme has.

Snippet to get all the menu locations of a WordPress theme

To see this and another 847 code snippets of this website, login or subscribe here.

In this snippet you use the get_nav_menu_locations function to get all the locations that a theme has registered and display it using the PHP function print_r.

Here you have a couple of examples of what it will show you:

  • Twenty Twenty-One Theme: Array ( [primary] => 2 [footer] => 2 )
    • 2 locations: primary and footer
  • Genesis Sample Theme: Array ( [primary] => 2 [secondary] => 2 )
    • 2 locations: primary and secondary

Remember to delete the snippet once you have obtained the locations.

Conclusions

Now you know how to get a list with all the menu locations registered by a WordPress theme.

Any questions? I read you in the comments.

And if you want to give me any suggestion for future tutorials, leave it in the contact form. Advantages of being a subscriber. 😉

PHP WordPress

To leave read and make questions about this code, you can login or register.

  • About OsomCode
  • FAQ
  • Contact

Legal Notice · Privacy Policy · Cookie Policy · Terms and conditions
Copyright © 2023

Lost your password?