PHP code example of nsrosenqvist / cmb2-nav-menus

1. Go to this page and download the library: Download nsrosenqvist/cmb2-nav-menus library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

nsrosenqvist / cmb2-nav-menus example snippets


// Add filter for locations
add_filter('cmb2_nav_menus', function($menu_slugs) {
    $menu_slugs[] = 'my_menu';

    return $menu_slugs;
}, 10, 1);

// For all menus
add_filters('cmb2_nav_menu_fields, function($fields) {
    // You can set ID both as the key and in the array
    $fields['icon-class'] = [
        'name' => __( 'Icon Class', 'theme' ),
        'type' => 'fontawesome_icon',
        'help' => 'Choose a FontAwesome icon class name (eg. fa-circle)',
    ];
}, 10, 1);

// For specific menu
add_filters('cmb2_nav_menu_fields_my_menu, function($fields) {
    // You can set ID both as the key and in the array
    $fields['disabled'] = [
        'name' => __( 'Disabled', 'theme' ),
        'type' => 'checkbox',
        'style' => 'thin',
    ];
}, 10, 1);

cmb2_get_nav_option($menu_item_id, $key = '', $default = null);