How Do I Add a Li Class to a WordPress Menu?

Adding aLi (or “Lightweight Icons”) class to a WordPress menu allows you to easily create a custom icon menu. To add the aLi class to your menu, open your WordPress theme’s functions.php file and add the following code:

function mytheme_menu() { wp_add_action( ‘wp_menu_items’, ‘mytheme_li_add_item’ ); } add_action( ‘wp_menu_items’, ‘mytheme_li_add_item’ ); function mytheme_li_add_item() { if ( is_admin() ) { $item = new WP_Menu_Item(); $item->name = ‘My Menu Item 1′; $item->description = ‘Description for My Menu Item 1′; $item->tax_class = ‘mytheme_li_tax'; $item->menu_icon = ‘assets/icon-menu-item-1.png'; $item->add_to_menu( ‘primary’, ‘My Menu Item 1′ ); } else { $item = new WP_Menu_Item(); $item->name = ‘My Menu Item 1′; $item->description = ‘Description for My Menu Item 1′; $item->tax_class = ‘mytheme_li_tax'; $item->menu_icon = ‘assets/icon-menu-item-1.png'; $item->add_to_menu( ‘secondary’, ‘My Menu Item 1′ ); } }

To add aLi icons to your menu, simply add the following line to your theme’s functions.php file:

add_action( ‘wp_menu_items’, ‘mytheme_li_add_item’ );

Once the aLi class is added to your menu, you can use the aLi_add_item() function to add an item to the menu.