Call WordPress Menu -8

Call WordPress Menu -8

Registered menu can be called using the wp_nav_menu function by their theme location name. and WordPress Navwalker class is used for the bootstrap css.Different ways to call the menu are as

Way 1: Simply Call the Menu

<?php wp_nav_menu(array(‘theme_location’ => ‘headerMenuLocation’))?>

Way 2:

Step 1: Download class-wp-bootstrap-Navwalker for css

Step 2: Then use the following code

 <?php

wp_nav_menu(array(

    ‘theme_location’ => ‘headerMenuLocation’,

    ‘depth’ => 2,

    ‘container’ => ‘div’,

    ‘container_class’ => ‘collapse navbar-collapse’,

    ‘container_id’ => ‘navbarSupportedContent’,

    ‘menu_class’ => ‘navbar-nav ml-auto mb-2 mb-lg-0 custm-mnu1’,

    ‘fallback_cb’ => ‘WP_Bootstrap_Navwalker::fallback’,

    ‘walker’ => new WP_Bootstrap_Navwalker(),

));

?>

Step 3: Use the following code in functions.php file to check the Navwalker file exist or not

//Bootstrap Navwalker

if (!file_exists(get_template_directory() . ‘/class-wp-bootstrap-navwalker.php’)) {

// File does not exist… return an error.

return new WP_Error (‘class-wp-bootstrap-navwalker-missing’, __(‘It appears the class-wp-bootstrap-navwalker.php file may be missing.’, ‘wp-bootstrap-navwalker’));

} else {

 / File exists… require it.

require_once get_template_directory (). ‘/class-wp-bootstrap-navwalker. php’;

}

Post Your Comments & Reviews

Your email address will not be published. Required fields are marked *

*

*