php - How Do I Retrieve a WordPress Menu and Submenu Item List
Get the solution ↓↓↓I'm currently using the below code to retrieve a list of all the menu items on a specific menu I have on my website. However ideally I'd like the sub menu items to have some sort of HTML class so I can add a class onto them or something similar. How would I go about doing this?
<?php
$primaryNav = wp_get_nav_menu_items(2);
foreach ( $primaryNav as $navItem ) {
echo '<li><a href="'.$navItem->url.'" title="'.$navItem->title.'">'.$navItem->title.'</a></li>';
}
?>
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: npm err! code 1
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.