I am trying to display icons in WP nav by using CSS class form menu section from backed.
I am using the following code to display nav but i dont know ho to call this class in link_before
<?php
wp_nav_menu( array(
'menu' => 'primary',
'theme_location' => 'primary',
'depth' => 3,
'menu_class' => 'nav navbar-nav',
'link_before' => '<i class="wht_to_do_here"></i>',
'fallback_cb' => 'wp_bootstrap_navwalker::fallback',
'walker' => new wp_bootstrap_navwalker())
);
?>
Thank’s in advance.
CSS Class from Back end is for the
<li>
tag. So first we need to remove that from<li>
.To remove it from
<li>
, add following code to your theme’s functions.php :Now we need to modify its anchor tag to add
<i>
tag into it. So for that add below code to your theme’s functions.php :As we have modified everything, you might not need to add
link_before
parameter inwp_nav_menu
function. So yourwp_nav_menu
will now look like :It’s done 🙂
NOTE : You can also do it by making your own menu walker.
Caution : By doing above method, it will apply to all menu and if you do not want to apply it to all menu thn probably you have to add condition with menu location.
You can add class through use of jQuery .addClass method or use css .nav::before{content: “f015”; font-family: ‘FontAwesome’;} method add this class in your css.