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 919 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
andfooter
- 2 locations:
- Genesis Sample Theme:
Array ( [primary] => 2 [secondary] => 2 )
- 2 locations:
primary
andsecondary
- 2 locations:
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. 😉