WP get menu ID by name and update nav menu

// WordPress Get Menu by Name
function wp_get_menu_id_by_name( $name ) {
    $menus = get_terms( 'nav_menu' ); 

    foreach ( $menus as $menu ) {
        if( $name === $menu->name ) {
            return $menu->term_id;
        }
    }
    return false;
}
$menu_id = wp_get_menu_id_by_name( "Menu 1" );

// Update Nav Menu
wp_update_nav_menu_item($menu_id , 12, array('menu-item-title' => __('HOME', 'landing'), 'menu-item-url' => home_url(), 'menu-item-status' => 'publish'));  

Leave a Reply