<\/script>')

Automatically adjust the menu in the "Main menu" menu when activating a theme

I am currently doing this menu: (Functions.php)

$menuname = 'Top Menu'; $menu_exists = wp_get_nav_menu_object( $menuname ); if( !$menu_exists){ $menu_id = wp_create_nav_menu($menuname); wp_update_nav_menu_item($menu_id, 0, array( 'menu-item-title' => __('Programme'), 'menu-item-classes' => 'programme', 'menu-item-url' => home_url( '/programme/' ), 'menu-item-status' => 'publish')); wp_update_nav_menu_item($menu_id, 0, array( 'menu-item-title' => __('Speakers'), 'menu-item-classes' => 'speakers', 'menu-item-url' => home_url( '/speakers/' ), 'menu-item-status' => 'publish')); } 

When I activate my theme, what I want to do is: Activating

The selection of the "Main menu" field is automatic, so when I start this topic, I create a menu and make it the main menu.

How to do it?

+6
source share
1 answer

You can programmatically configure the theme_location menu:

 $locations = get_theme_mod('nav_menu_locations'); $locations['primary-menu'] = $term_id_of_menu; set_theme_mod( 'nav_menu_locations', $locations ); 

Add this to your functions.php .

+11
source

Source: https://habr.com/ru/post/956076/


All Articles