How Do I Display Images in WordPress Menu?

Images can be displayed in WordPress menus by using the wp_nav_menu() function. This function takes two parameters: the list of menu items to display, and the image to display for each item. The following example displays the image for the menu item titled “My Menu Item” in the main menu of the website:

‘my-menu-item’, ‘menu_item_title’ => ‘My Menu Item’, ‘submenu_id’ => ‘submenu-1′, ‘submenu_title’ => ‘Sub Menu 1′, ‘parent_id’ => ”, ‘position’ => 2, ‘type’ => ‘image’, ‘alt’ => __( ‘My Menu Item Image’, ‘mytheme’ ), ‘title_captions’ => array( ‘My Menu Item Image’ => ‘This is the text for the image displayed for My Menu Item.’, ‘Sub Menu 1 Image’ => ‘This is the text for the image displayed for Sub Menu 1.’ ) ) );

The first parameter is the menu item ID. The second parameter is the menu item title. The third parameter is the submenu ID. The fourth parameter is the submenu title. The fifth parameter is the parent menu item ID.

The sixth parameter is the position in the main menu. The seventh parameter is the type of menu item: image or text. The eighth parameter is the alt text for the menu item. The ninth parameter is the title captions for the menu item.