Skip to content
Advertisement

WordPress/PHP get list of all links in primary navigation

I am trying to create a list of all links in primary navigation on my WordPress site. I am trying to output the link as URL: in a script tag using a foreach loop.

I am stuck trying to list of of the navitems links using $navItem->url in my foreach loop. It doesn’t return anything / false.

Instead of $locations[$menuLocations] I have tried simply just write primary menu name as well: $locations[‘primary’] but no luck so far.

JavaScript

Advertisement

Answer

Well… I did a refactor of your code and it’s works 😉

Try with this way:

JavaScript

Regards!

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement