• Menu: edit items

    Read more

    To edit individual items of a menu

    add_filter( 'wp_nav_menu_objects', 'dev__add_smiley', 11, 2 );
    
    function dev__add_smiley( $items, $args ) {
    
    	foreach ( $items as &$item ) {
    
    		// add class
    		array_push($item->classes, 'dw-submenu__parent');
    			
    		$item->title = ':D ' . $item->title;
    
    		// $item->title .= '</a>' . $subelement; note: close the link
    
    		}
    
    	}
    
    	return $items;
    
    }

    Sources:

    • https://developer.wordpress.org/reference/hooks/wp_nav_menu_items/
    • https://developer.wordpress.org/reference/hooks/wp_nav_menu_objects/
  • Register navigation menu

    Read more

    To register a menu :

    add_action( 'init', 'dev__register_menu' );
    
    function dev__register_menu() {
    
    	register_nav_menus(array(
    		'primary' => __( 'Primary Navigation', 'dev' ),
    		'secondary' => __( 'Secondary Navigation', 'dev' ),
    	));
    }