I would like to add the Wordpress menu items to a series of divs (this could be a list as well). How would i go about doing this?

Basically in the code below, I want the content shown in each div to come from the backend of WP. It's for a section I am adding to a page.


Many thanks in advance


1 Answer 1


assuming you are adding this into a page template:

$menu_list = wp_get_nav_menu_items( 'All Pages' );

if( $menu_list ) foreach( $menu_list as $menu_item ) {
    if( $menu_item->menu_item_parent == 0 ) {
        echo '<div><a href="' . $menu_item->url . '">' . $menu_item->title . '</a></div>';

the above shows only top menu items with their links, no dropdowns.

replace 'All Pages' with the name of your menu. based on https://developer.wordpress.org/reference/functions/wp_get_nav_menu_items/:


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.