<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Bootstrap Menu In WordPress Archives - Codeplaners</title>
	<atom:link href="https://codeplaners.com/tag/bootstrap-menu-in-wordpress/feed/" rel="self" type="application/rss+xml" />
	<link>https://codeplaners.com/tag/bootstrap-menu-in-wordpress/</link>
	<description>Code Solution</description>
	<lastBuildDate>Tue, 25 Jun 2024 01:53:33 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.1.7</generator>

<image>
	<url>https://codeplaners.com/wp-content/uploads/2020/09/cropped-favicon-social-32x32.png</url>
	<title>Bootstrap Menu In WordPress Archives - Codeplaners</title>
	<link>https://codeplaners.com/tag/bootstrap-menu-in-wordpress/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>How To Add Bootstrap Menu In WordPress</title>
		<link>https://codeplaners.com/how-to-add-bootstrap-menu-in-wordpress/</link>
					<comments>https://codeplaners.com/how-to-add-bootstrap-menu-in-wordpress/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Tue, 25 Jun 2024 01:53:33 +0000</pubDate>
				<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[Bootstrap Menu In WordPress]]></category>
		<guid isPermaLink="false">https://codeplaners.com/?p=1722</guid>

					<description><![CDATA[<p>Hi Dev, Today, we will show you How To Add Bootstrap Menu In WordPress. This article will give you simple example of How To Add Bootstrap Menu In WordPress. Let&#8217;s discuss How To Add Bootstrap Menu In WordPress. In this article, we will implement a How To Add Bootstrap Menu In WordPress. So let’s follow &#8230; <a href="https://codeplaners.com/how-to-add-bootstrap-menu-in-wordpress/" class="more-link">Continue reading<span class="screen-reader-text"> "How To Add Bootstrap Menu In WordPress"</span></a></p>
<p>The post <a rel="nofollow" href="https://codeplaners.com/how-to-add-bootstrap-menu-in-wordpress/">How To Add Bootstrap Menu In WordPress</a> appeared first on <a rel="nofollow" href="https://codeplaners.com">Codeplaners</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Hi Dev,</p>
<p>Today, we will show you How To Add Bootstrap Menu In WordPress. This article will give you simple example of How To Add Bootstrap Menu In WordPress. Let&#8217;s discuss How To Add Bootstrap Menu In WordPress. In this article, we will implement a How To Add Bootstrap Menu In WordPress.</p>
<p>So let’s follow few step to create example of How To Add Bootstrap Menu In WordPress.</p>
<h3 class="step_code">Step 1: Create class-wp-bootstrap-navwalker.php file </h3>
<p><strong>You need to create this file in your theme (wp-content\themes\codeplaners\class-wp-bootstrap-navwalker.php</strong><br />
After creating the file, enter the code given below</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
/**
 * WP Bootstrap Navwalker
 *
 * @package WP-Bootstrap-Navwalker
 *
 * @wordpress-plugin
 * Plugin Name: WP Bootstrap Navwalker
 * Plugin URI:  https://github.com/wp-bootstrap/wp-bootstrap-navwalker
 * Description: A custom WordPress nav walker class to implement the Bootstrap 4 navigation style in a custom theme using the WordPress built in menu manager.
 * Author: Edward McIntyre - @twittem, WP Bootstrap, William Patton - @pattonwebz, IanDelMar - @IanDelMar
 * Version: 4.3.0
 * Author URI: https://github.com/wp-bootstrap
 * GitHub Plugin URI: https://github.com/wp-bootstrap/wp-bootstrap-navwalker
 * GitHub Branch: master
 * License: GPL-3.0+
 * License URI: http://www.gnu.org/licenses/gpl-3.0.txt
 */

// Check if Class Exists.
if ( ! class_exists( 'WP_Bootstrap_Navwalker' ) ) :
	/**
	 * WP_Bootstrap_Navwalker class.
	 */
	class WP_Bootstrap_Navwalker extends Walker_Nav_Menu {

		/**
		 * Whether the items_wrap contains schema microdata or not.
		 *
		 * @since 4.2.0
		 * @var boolean
		 */
		private $has_schema = false;

		/**
		 * Ensure the items_wrap argument contains microdata.
		 *
		 * @since 4.2.0
		 */
		public function __construct() {
			if ( ! has_filter( 'wp_nav_menu_args', array( $this, 'add_schema_to_navbar_ul' ) ) ) {
				add_filter( 'wp_nav_menu_args', array( $this, 'add_schema_to_navbar_ul' ) );
			}
		}

		/**
		 * Starts the list before the elements are added.
		 *
		 * @since WP 3.0.0
		 *
		 * @see Walker_Nav_Menu::start_lvl()
		 *
		 * @param string           $output Used to append additional content (passed by reference).
		 * @param int              $depth  Depth of menu item. Used for padding.
		 * @param WP_Nav_Menu_Args $args   An object of wp_nav_menu() arguments.
		 */
		public function start_lvl( &amp;$output, $depth = 0, $args = null ) {
			if ( isset( $args-&gt;item_spacing ) &amp;&amp; 'discard' === $args-&gt;item_spacing ) {
				$t = '';
				$n = '';
			} else {
				$t = &quot;\t&quot;;
				$n = &quot;\n&quot;;
			}
			$indent = str_repeat( $t, $depth );
			// Default class to add to the file.
			$classes = array( 'dropdown-menu' );
			/**
			 * Filters the CSS class(es) applied to a menu list element.
			 *
			 * @since WP 4.8.0
			 *
			 * @param array    $classes The CSS classes that are applied to the menu `&lt;ul&gt;` element.
			 * @param stdClass $args    An object of `wp_nav_menu()` arguments.
			 * @param int      $depth   Depth of menu item. Used for padding.
			 */
			$class_names = join( ' ', apply_filters( 'nav_menu_submenu_css_class', $classes, $args, $depth ) );
			$class_names = $class_names ? ' class=&quot;' . esc_attr( $class_names ) . '&quot;' : '';

			/*
			 * The `.dropdown-menu` container needs to have a labelledby
			 * attribute which points to it's trigger link.
			 *
			 * Form a string for the labelledby attribute from the the latest
			 * link with an id that was added to the $output.
			 */
			$labelledby = '';
			// Find all links with an id in the output.
			preg_match_all( '/(&lt;a.*?id=\&quot;|\')(.*?)\&quot;|\'.*?&gt;/im', $output, $matches );
			// With pointer at end of array check if we got an ID match.
			if ( end( $matches&#x5B;2] ) ) {
				// Build a string to use as aria-labelledby.
				$labelledby = 'aria-labelledby=&quot;' . esc_attr( end( $matches&#x5B;2] ) ) . '&quot;';
			}
			$output .= &quot;{$n}{$indent}&lt;ul$class_names $labelledby&gt;{$n}&quot;;
		}

		/**
		 * Starts the element output.
		 *
		 * @since WP 3.0.0
		 * @since WP 4.4.0 The {@see 'nav_menu_item_args'} filter was added.
		 *
		 * @see Walker_Nav_Menu::start_el()
		 *
		 * @param string           $output Used to append additional content (passed by reference).
		 * @param WP_Nav_Menu_Item $item   Menu item data object.
		 * @param int              $depth  Depth of menu item. Used for padding.
		 * @param WP_Nav_Menu_Args $args   An object of wp_nav_menu() arguments.
		 * @param int              $id     Current item ID.
		 */
		public function start_el( &amp;$output, $item, $depth = 0, $args = null, $id = 0 ) {
			if ( isset( $args-&gt;item_spacing ) &amp;&amp; 'discard' === $args-&gt;item_spacing ) {
				$t = '';
				$n = '';
			} else {
				$t = &quot;\t&quot;;
				$n = &quot;\n&quot;;
			}
			$indent = ( $depth ) ? str_repeat( $t, $depth ) : '';

			if ( false !== strpos( $args-&gt;items_wrap, 'itemscope' ) &amp;&amp; false === $this-&gt;has_schema ) {
				$this-&gt;has_schema  = true;
				$args-&gt;link_before = '&lt;span itemprop=&quot;name&quot;&gt;' . $args-&gt;link_before;
				$args-&gt;link_after .= '&lt;/span&gt;';
			}

			$classes = empty( $item-&gt;classes ) ? array() : (array) $item-&gt;classes;

			// Updating the CSS classes of a menu item in the WordPress Customizer preview results in all classes defined
			// in that particular input box to come in as one big class string.
			$split_on_spaces = function ( $class ) {
				return preg_split( '/\s+/', $class );
			};
			$classes         = $this-&gt;flatten( array_map( $split_on_spaces, $classes ) );

			/*
			 * Initialize some holder variables to store specially handled item
			 * wrappers and icons.
			 */
			$linkmod_classes = array();
			$icon_classes    = array();

			/*
			 * Get an updated $classes array without linkmod or icon classes.
			 *
			 * NOTE: linkmod and icon class arrays are passed by reference and
			 * are maybe modified before being used later in this function.
			 */
			$classes = $this-&gt;separate_linkmods_and_icons_from_classes( $classes, $linkmod_classes, $icon_classes, $depth );

			// Join any icon classes plucked from $classes into a string.
			$icon_class_string = join( ' ', $icon_classes );

			/**
			 * Filters the arguments for a single nav menu item.
			 *
			 * @since WP 4.4.0
			 *
			 * @param WP_Nav_Menu_Args $args  An object of wp_nav_menu() arguments.
			 * @param WP_Nav_Menu_Item $item  Menu item data object.
			 * @param int              $depth Depth of menu item. Used for padding.
			 *
			 * @var WP_Nav_Menu_Args
			 */
			$args = apply_filters( 'nav_menu_item_args', $args, $item, $depth );

			// Add .dropdown or .active classes where they are needed.
			if ( $this-&gt;has_children ) {
				$classes&#x5B;] = 'dropdown';
			}
			if ( in_array( 'current-menu-item', $classes, true ) || in_array( 'current-menu-parent', $classes, true ) ) {
				$classes&#x5B;] = 'active';
			}

			// Add some additional default classes to the item.
			$classes&#x5B;] = 'menu-item-' . $item-&gt;ID;
			$classes&#x5B;] = 'nav-item';

			// Allow filtering the classes.
			$classes = apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item, $args, $depth );

			// Form a string of classes in format: class=&quot;class_names&quot;.
			$class_names = join( ' ', $classes );
			$class_names = $class_names ? ' class=&quot;' . esc_attr( $class_names ) . '&quot;' : '';

			/**
			 * Filters the ID applied to a menu item's list item element.
			 *
			 * @since WP 3.0.1
			 * @since WP 4.1.0 The `$depth` parameter was added.
			 *
			 * @param string           $menu_id The ID that is applied to the menu item's `&lt;li&gt;` element.
			 * @param WP_Nav_Menu_Item $item    The current menu item.
			 * @param WP_Nav_Menu_Args $args    An object of wp_nav_menu() arguments.
			 * @param int              $depth   Depth of menu item. Used for padding.
			 */
			$id = apply_filters( 'nav_menu_item_id', 'menu-item-' . $item-&gt;ID, $item, $args, $depth );
			$id = $id ? ' id=&quot;' . esc_attr( $id ) . '&quot;' : '';

			$output .= $indent . '&lt;li ' . $id . $class_names . '&gt;';

			// Initialize array for holding the $atts for the link item.
			$atts           = array();
			$atts&#x5B;'title']  = ! empty( $item-&gt;attr_title ) ? $item-&gt;attr_title : '';
			$atts&#x5B;'target'] = ! empty( $item-&gt;target ) ? $item-&gt;target : '';
			if ( '_blank' === $item-&gt;target &amp;&amp; empty( $item-&gt;xfn ) ) {
				$atts&#x5B;'rel'] = 'noopener noreferrer';
			} else {
				$atts&#x5B;'rel'] = ! empty( $item-&gt;xfn ) ? $item-&gt;xfn : '';
			}

			// If the item has_children add atts to &lt;a&gt;.
			if ( $this-&gt;has_children &amp;&amp; 0 === $depth ) {
				$atts&#x5B;'href']          = '#';
				$atts&#x5B;'data-toggle']   = 'dropdown';
				$atts&#x5B;'aria-expanded'] = 'false';
				$atts&#x5B;'class']         = 'dropdown-toggle nav-link';
				$atts&#x5B;'id']            = 'menu-item-dropdown-' . $item-&gt;ID;
			} else {
				if ( true === $this-&gt;has_schema ) {
					$atts&#x5B;'itemprop'] = 'url';
				}

				$atts&#x5B;'href'] = ! empty( $item-&gt;url ) ? $item-&gt;url : '#';
				// For items in dropdowns use .dropdown-item instead of .nav-link.
				if ( $depth &gt; 0 ) {
					$atts&#x5B;'class'] = 'dropdown-item';
				} else {
					$atts&#x5B;'class'] = 'nav-link';
				}
			}

			$atts&#x5B;'aria-current'] = $item-&gt;current ? 'page' : '';

			// Update atts of this item based on any custom linkmod classes.
			$atts = $this-&gt;update_atts_for_linkmod_type( $atts, $linkmod_classes );

			// Allow filtering of the $atts array before using it.
			$atts = apply_filters( 'nav_menu_link_attributes', $atts, $item, $args, $depth );

			// Build a string of html containing all the atts for the item.
			$attributes = '';
			foreach ( $atts as $attr =&gt; $value ) {
				if ( ! empty( $value ) ) {
					$value       = ( 'href' === $attr ) ? esc_url( $value ) : esc_attr( $value );
					$attributes .= ' ' . $attr . '=&quot;' . $value . '&quot;';
				}
			}

			// Set a typeflag to easily test if this is a linkmod or not.
			$linkmod_type = $this-&gt;get_linkmod_type( $linkmod_classes );

			// START appending the internal item contents to the output.
			$item_output = isset( $args-&gt;before ) ? $args-&gt;before : '';

			/*
			 * This is the start of the internal nav item. Depending on what
			 * kind of linkmod we have we may need different wrapper elements.
			 */
			if ( '' !== $linkmod_type ) {
				// Is linkmod, output the required element opener.
				$item_output .= $this-&gt;linkmod_element_open( $linkmod_type, $attributes );
			} else {
				// With no link mod type set this must be a standard &lt;a&gt; tag.
				$item_output .= '&lt;a' . $attributes . '&gt;';
			}

			/*
			 * Initiate empty icon var, then if we have a string containing any
			 * icon classes form the icon markup with an &lt;i&gt; element. This is
			 * output inside of the item before the $title (the link text).
			 */
			$icon_html = '';
			if ( ! empty( $icon_class_string ) ) {
				// Append an &lt;i&gt; with the icon classes to what is output before links.
				$icon_html = '&lt;i class=&quot;' . esc_attr( $icon_class_string ) . '&quot; aria-hidden=&quot;true&quot;&gt;&lt;/i&gt; ';
			}

			/** This filter is documented in wp-includes/post-template.php */
			$title = apply_filters( 'the_title', $item-&gt;title, $item-&gt;ID );

			/**
			 * Filters a menu item's title.
			 *
			 * @since WP 4.4.0
			 *
			 * @param string           $title The menu item's title.
			 * @param WP_Nav_Menu_Item $item  The current menu item.
			 * @param WP_Nav_Menu_Args $args  An object of wp_nav_menu() arguments.
			 * @param int              $depth Depth of menu item. Used for padding.
			 */
			$title = apply_filters( 'nav_menu_item_title', $title, $item, $args, $depth );

			// If the .sr-only class was set apply to the nav items text only.
			if ( in_array( 'sr-only', $linkmod_classes, true ) ) {
				$title         = $this-&gt;wrap_for_screen_reader( $title );
				$keys_to_unset = array_keys( $linkmod_classes, 'sr-only', true );
				foreach ( $keys_to_unset as $k ) {
					unset( $linkmod_classes&#x5B; $k ] );
				}
			}

			// Put the item contents into $output.
			$item_output .= isset( $args-&gt;link_before ) ? $args-&gt;link_before . $icon_html . $title . $args-&gt;link_after : '';

			/*
			 * This is the end of the internal nav item. We need to close the
			 * correct element depending on the type of link or link mod.
			 */
			if ( '' !== $linkmod_type ) {
				// Is linkmod, output the required closing element.
				$item_output .= $this-&gt;linkmod_element_close( $linkmod_type );
			} else {
				// With no link mod type set this must be a standard &lt;a&gt; tag.
				$item_output .= '&lt;/a&gt;';
			}

			$item_output .= isset( $args-&gt;after ) ? $args-&gt;after : '';

			// END appending the internal item contents to the output.
			$output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
		}

		/**
		 * Menu fallback.
		 *
		 * If this function is assigned to the wp_nav_menu's fallback_cb variable
		 * and a menu has not been assigned to the theme location in the WordPress
		 * menu manager the function will display nothing to a non-logged in user,
		 * and will add a link to the WordPress menu manager if logged in as an admin.
		 *
		 * @param array $args passed from the wp_nav_menu function.
		 * @return string|void String when echo is false.
		 */
		public static function fallback( $args ) {
			if ( ! current_user_can( 'edit_theme_options' ) ) {
				return;
			}

			// Initialize var to store fallback html.
			$fallback_output = '';

			// Menu container opening tag.
			$show_container = false;
			if ( $args&#x5B;'container'] ) {
				/**
				 * Filters the list of HTML tags that are valid for use as menu containers.
				 *
				 * @since WP 3.0.0
				 *
				 * @param array $tags The acceptable HTML tags for use as menu containers.
				 *                    Default is array containing 'div' and 'nav'.
				 */
				$allowed_tags = apply_filters( 'wp_nav_menu_container_allowedtags', array( 'div', 'nav' ) );
				if ( is_string( $args&#x5B;'container'] ) &amp;&amp; in_array( $args&#x5B;'container'], $allowed_tags, true ) ) {
					$show_container   = true;
					$class            = $args&#x5B;'container_class'] ? ' class=&quot;menu-fallback-container ' . esc_attr( $args&#x5B;'container_class'] ) . '&quot;' : ' class=&quot;menu-fallback-container&quot;';
					$id               = $args&#x5B;'container_id'] ? ' id=&quot;' . esc_attr( $args&#x5B;'container_id'] ) . '&quot;' : '';
					$fallback_output .= '&lt;' . $args&#x5B;'container'] . $id . $class . '&gt;';
				}
			}

			// The fallback menu.
			$class            = $args&#x5B;'menu_class'] ? ' class=&quot;menu-fallback-menu ' . esc_attr( $args&#x5B;'menu_class'] ) . '&quot;' : ' class=&quot;menu-fallback-menu&quot;';
			$id               = $args&#x5B;'menu_id'] ? ' id=&quot;' . esc_attr( $args&#x5B;'menu_id'] ) . '&quot;' : '';
			$fallback_output .= '&lt;ul' . $id . $class . '&gt;';
			$fallback_output .= '&lt;li class=&quot;nav-item&quot;&gt;&lt;a href=&quot;' . esc_url( admin_url( 'nav-menus.php' ) ) . '&quot; class=&quot;nav-link&quot; title=&quot;' . esc_attr__( 'Add a menu', 'wp-bootstrap-navwalker' ) . '&quot;&gt;' . esc_html__( 'Add a menu', 'wp-bootstrap-navwalker' ) . '&lt;/a&gt;&lt;/li&gt;';
			$fallback_output .= '&lt;/ul&gt;';

			// Menu container closing tag.
			if ( $show_container ) {
				$fallback_output .= '&lt;/' . $args&#x5B;'container'] . '&gt;';
			}

			// if $args has 'echo' key and it's true echo, otherwise return.
			if ( array_key_exists( 'echo', $args ) &amp;&amp; $args&#x5B;'echo'] ) {
				// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
				echo $fallback_output;
			} else {
				return $fallback_output;
			}
		}

		/**
		 * Filter to ensure the items_Wrap argument contains microdata.
		 *
		 * @since 4.2.0
		 *
		 * @param  array $args The nav instance arguments.
		 * @return array $args The altered nav instance arguments.
		 */
		public function add_schema_to_navbar_ul( $args ) {
			if ( isset( $args&#x5B;'items_wrap'] ) ) {
				$wrap = $args&#x5B;'items_wrap'];
				if ( strpos( $wrap, 'SiteNavigationElement' ) === false ) {
					$args&#x5B;'items_wrap'] = preg_replace( '/(&gt;).*&gt;?\%3\$s/', ' itemscope itemtype=&quot;http://www.schema.org/SiteNavigationElement&quot;$0', $wrap );
				}
			}
			return $args;
		}

		/**
		 * Find any custom linkmod or icon classes and store in their holder
		 * arrays then remove them from the main classes array.
		 *
		 * Supported linkmods: .disabled, .dropdown-header, .dropdown-divider, .sr-only
		 * Supported iconsets: Font Awesome 4/5, Glypicons
		 *
		 * NOTE: This accepts the linkmod and icon arrays by reference.
		 *
		 * @since 4.0.0
		 *
		 * @param array   $classes         an array of classes currently assigned to the item.
		 * @param array   $linkmod_classes an array to hold linkmod classes.
		 * @param array   $icon_classes    an array to hold icon classes.
		 * @param integer $depth           an integer holding current depth level.
		 *
		 * @return array  $classes         a maybe modified array of classnames.
		 */
		private function separate_linkmods_and_icons_from_classes( $classes, &amp;$linkmod_classes, &amp;$icon_classes, $depth ) {
			// Loop through $classes array to find linkmod or icon classes.
			foreach ( $classes as $key =&gt; $class ) {
				/*
				 * If any special classes are found, store the class in it's
				 * holder array and and unset the item from $classes.
				 */
				if ( preg_match( '/^disabled|^sr-only/i', $class ) ) {
					// Test for .disabled or .sr-only classes.
					$linkmod_classes&#x5B;] = $class;
					unset( $classes&#x5B; $key ] );
				} elseif ( preg_match( '/^dropdown-header|^dropdown-divider|^dropdown-item-text/i', $class ) &amp;&amp; $depth &gt; 0 ) {
					/*
					 * Test for .dropdown-header or .dropdown-divider and a
					 * depth greater than 0 - IE inside a dropdown.
					 */
					$linkmod_classes&#x5B;] = $class;
					unset( $classes&#x5B; $key ] );
				} elseif ( preg_match( '/^fa-(\S*)?|^fa(s|r|l|b)?(\s?)?$/i', $class ) ) {
					// Font Awesome.
					$icon_classes&#x5B;] = $class;
					unset( $classes&#x5B; $key ] );
				} elseif ( preg_match( '/^glyphicon-(\S*)?|^glyphicon(\s?)$/i', $class ) ) {
					// Glyphicons.
					$icon_classes&#x5B;] = $class;
					unset( $classes&#x5B; $key ] );
				}
			}

			return $classes;
		}

		/**
		 * Return a string containing a linkmod type and update $atts array
		 * accordingly depending on the decided.
		 *
		 * @since 4.0.0
		 *
		 * @param array $linkmod_classes array of any link modifier classes.
		 *
		 * @return string                empty for default, a linkmod type string otherwise.
		 */
		private function get_linkmod_type( $linkmod_classes = array() ) {
			$linkmod_type = '';
			// Loop through array of linkmod classes to handle their $atts.
			if ( ! empty( $linkmod_classes ) ) {
				foreach ( $linkmod_classes as $link_class ) {
					if ( ! empty( $link_class ) ) {

						// Check for special class types and set a flag for them.
						if ( 'dropdown-header' === $link_class ) {
							$linkmod_type = 'dropdown-header';
						} elseif ( 'dropdown-divider' === $link_class ) {
							$linkmod_type = 'dropdown-divider';
						} elseif ( 'dropdown-item-text' === $link_class ) {
							$linkmod_type = 'dropdown-item-text';
						}
					}
				}
			}
			return $linkmod_type;
		}

		/**
		 * Update the attributes of a nav item depending on the limkmod classes.
		 *
		 * @since 4.0.0
		 *
		 * @param array $atts            array of atts for the current link in nav item.
		 * @param array $linkmod_classes an array of classes that modify link or nav item behaviors or displays.
		 *
		 * @return array                 maybe updated array of attributes for item.
		 */
		private function update_atts_for_linkmod_type( $atts = array(), $linkmod_classes = array() ) {
			if ( ! empty( $linkmod_classes ) ) {
				foreach ( $linkmod_classes as $link_class ) {
					if ( ! empty( $link_class ) ) {
						/*
						 * Update $atts with a space and the extra classname
						 * so long as it's not a sr-only class.
						 */
						if ( 'sr-only' !== $link_class ) {
							$atts&#x5B;'class'] .= ' ' . esc_attr( $link_class );
						}
						// Check for special class types we need additional handling for.
						if ( 'disabled' === $link_class ) {
							// Convert link to '#' and unset open targets.
							$atts&#x5B;'href'] = '#';
							unset( $atts&#x5B;'target'] );
						} elseif ( 'dropdown-header' === $link_class || 'dropdown-divider' === $link_class || 'dropdown-item-text' === $link_class ) {
							// Store a type flag and unset href and target.
							unset( $atts&#x5B;'href'] );
							unset( $atts&#x5B;'target'] );
						}
					}
				}
			}
			return $atts;
		}

		/**
		 * Wraps the passed text in a screen reader only class.
		 *
		 * @since 4.0.0
		 *
		 * @param string $text the string of text to be wrapped in a screen reader class.
		 * @return string      the string wrapped in a span with the class.
		 */
		private function wrap_for_screen_reader( $text = '' ) {
			if ( $text ) {
				$text = '&lt;span class=&quot;sr-only&quot;&gt;' . $text . '&lt;/span&gt;';
			}
			return $text;
		}

		/**
		 * Returns the correct opening element and attributes for a linkmod.
		 *
		 * @since 4.0.0
		 *
		 * @param string $linkmod_type a sting containing a linkmod type flag.
		 * @param string $attributes   a string of attributes to add to the element.
		 *
		 * @return string              a string with the openign tag for the element with attribibutes added.
		 */
		private function linkmod_element_open( $linkmod_type, $attributes = '' ) {
			$output = '';
			if ( 'dropdown-item-text' === $linkmod_type ) {
				$output .= '&lt;span class=&quot;dropdown-item-text&quot;' . $attributes . '&gt;';
			} elseif ( 'dropdown-header' === $linkmod_type ) {
				/*
				 * For a header use a span with the .h6 class instead of a real
				 * header tag so that it doesn't confuse screen readers.
				 */
				$output .= '&lt;span class=&quot;dropdown-header h6&quot;' . $attributes . '&gt;';
			} elseif ( 'dropdown-divider' === $linkmod_type ) {
				// This is a divider.
				$output .= '&lt;div class=&quot;dropdown-divider&quot;' . $attributes . '&gt;';
			}
			return $output;
		}

		/**
		 * Return the correct closing tag for the linkmod element.
		 *
		 * @since 4.0.0
		 *
		 * @param string $linkmod_type a string containing a special linkmod type.
		 *
		 * @return string              a string with the closing tag for this linkmod type.
		 */
		private function linkmod_element_close( $linkmod_type ) {
			$output = '';
			if ( 'dropdown-header' === $linkmod_type || 'dropdown-item-text' === $linkmod_type ) {
				/*
				 * For a header use a span with the .h6 class instead of a real
				 * header tag so that it doesn't confuse screen readers.
				 */
				$output .= '&lt;/span&gt;';
			} elseif ( 'dropdown-divider' === $linkmod_type ) {
				// This is a divider.
				$output .= '&lt;/div&gt;';
			}
			return $output;
		}

		/**
		 * Flattens a multidimensional array to a simple array.
		 *
		 * @param array $array a multidimensional array.
		 *
		 * @return array a simple array
		 */
		public function flatten( $array ) {
			$result = array();
			foreach ( $array as $element ) {
				if ( is_array( $element ) ) {
					array_push( $result, ...$this-&gt;flatten( $element ) );
				} else {
					$result&#x5B;] = $element;
				}
			}
			return $result;
		}

	}

endif;
</pre>
<h3 class="step_code">Step 2: Bootstrap menu function:</h3>
<p><strong>funcation.php</strong></p>
<pre class="brush: php; title: ; notranslate">
/**
 * Register Custom Navigation Walker
 */
function register_navwalker(){
    require_once get_template_directory() . '/class-wp-bootstrap-navwalker.php';
}
add_action( 'after_setup_theme', 'register_navwalker' );
</pre>
<h3 class="step_code">Step 3: Add the code below to your theme&#8217;s header.php file.</h3>
<pre class="brush: php; title: ; notranslate">
&lt;nav class=&quot;navbar navbar-expand-md navbar-light bg-light&quot; role=&quot;navigation&quot;&gt;
  &lt;div class=&quot;container&quot;&gt;
    &lt;!-- Brand and toggle get grouped for better mobile display --&gt;
    &lt;button class=&quot;navbar-toggler&quot; type=&quot;button&quot; data-toggle=&quot;collapse&quot; data-target=&quot;#bs-example-navbar-collapse-1&quot; aria-controls=&quot;bs-example-navbar-collapse-1&quot; aria-expanded=&quot;false&quot; aria-label=&quot;&lt;?php esc_attr_e( 'Toggle navigation', 'your-theme-slug' ); ?&gt;&quot;&gt;
        &lt;span class=&quot;navbar-toggler-icon&quot;&gt;&lt;/span&gt;
    &lt;/button&gt;
    &lt;a class=&quot;navbar-brand&quot; href=&quot;#&quot;&gt;Navbar&lt;/a&gt;
        &lt;?php
        wp_nav_menu( array(
            'theme_location'    =&gt; 'primary',
            'depth'             =&gt; 2,
            'container'         =&gt; 'div',
            'container_class'   =&gt; 'collapse navbar-collapse',
            'container_id'      =&gt; 'bs-example-navbar-collapse-1',
            'menu_class'        =&gt; 'nav navbar-nav',
            'fallback_cb'       =&gt; 'WP_Bootstrap_Navwalker::fallback',
            'walker'            =&gt; new WP_Bootstrap_Navwalker(),
        ) );
        ?&gt;
    &lt;/div&gt;
&lt;/nav&gt;
</pre>
<p><strong>If you are facing any problem then you can also watch the video</strong></p>
<p><strong>I hope it will assist you…</strong></p>
<p>The post <a rel="nofollow" href="https://codeplaners.com/how-to-add-bootstrap-menu-in-wordpress/">How To Add Bootstrap Menu In WordPress</a> appeared first on <a rel="nofollow" href="https://codeplaners.com">Codeplaners</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://codeplaners.com/how-to-add-bootstrap-menu-in-wordpress/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
