Bài viết này thực hiện (hoặc lụm bài về đăng câu like từ các trang khác) bởi Việt Lâm Coder một YOUTUBER có tâm và đẹp trai siêu cấp vô địch zũ trụ. Các bạn đi ngang nếu được cho Lâm 1 like và 1 đăng ký kênh Youtube nhé !!
Bootstrap, is one of the most popular front-end framework for your site development. It has been used by millions of site for its development. Now, since the major update 4 has been released, there are many changes in this framework. You can find the change log for this here. As you can also notice that, Bootstrap has changed the way it integrates the menu in it. So, here we will discuss about how to integrate Bootstrap NavBar 4 into WordPress theme.
As of earlier for Bootstrap version 3, we have already discussed about how to integrate it in WordPress theme in our previous post. But, if you want to have a look on that instead about how to do it, then, you can find it here.
What is Bootstrap?
First of all, let’s have a surface knowledge on Bootstrap framework, shall we? Well, Bootstrap is the front-end development framework, which is most popular among many of the website developers and designers. It is developed in such a way, in which the mobile first friendly step is taken.
While you develop a theme via Bootstrap, then, your site will be automatically mobile friendly since this framework is mobile friendly. It also has lots of integrated features inside it just like, tabs, carousels, etc. So, due to this, you may rarely require any of the other JS library at all for your site development.
Also, this framework, Bootstrap, is hosted on GitHub too, you can find it here. It means that, it is open source compatible and anyone can contribute on it’s development.
How to Integrate Bootstrap NavBar 4 into WordPress theme?
Now, since you have the surfaced background on Bootstrap, you may notice that, it has different way in displaying the NavBar than the native WordPress way, right? Well, if you could not notice then, you can find about it here, in their documentation. Now, you will clearly notice that it is totally different.
Now, you may be in confusion about how to do it, right? Well, do not get confused on this. Here, we will be discussing about how to do it. So, why the wait, let’s move ahead and integrate Bootstrap NavBar 4 into your built WordPress theme.
First of all, what you have to do is, you can download the Bootstrap NavWalker class from here. Now, after that, you can copy the file bootstrap-navwalker from that repo inside your theme’s directory, ie, inside /wp-content/themes/theme-name/ folder.
Now, after you have added that file inside the theme’s folder, you need to require that function as in the below PHP code, adding it in the functions.php file of your theme:
1 |
require get_template_directory() . '/bootstrap-navwalker.php'; |
After that, assuming that you have already registered the nav menu for your theme, now, let’s move ahead and integrate Bootstrap NavBar 4 for your theme. For that, what you have to do is, you need to call that newly created class via the wp_nav_menu()
function as in the below example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
<nav class="navbar navbar-expand-lg navbar-light bg-light"> <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbar-content" aria-controls="navbar-content" aria-expanded="false" aria-label="<?php esc_html_e( 'Toggle Navigation', 'theme-textdomain' ); ?>"> <span class="navbar-toggler-icon"></span> </button> <div class="collapse navbar-collapse" id="navbar-content"> <?php wp_nav_menu( array( 'theme_location' => 'menu-1', // Defined when registering the menu 'menu_id' => 'primary-menu', 'container' => false, 'depth' => 2, 'menu_class' => 'navbar-nav ml-auto', 'walker' => new Bootstrap_NavWalker(), // This controls the display of the Bootstrap Navbar 'fallback_cb' => 'Bootstrap_NavWalker::fallback', // For menu fallback ) ); ?> </div> </nav> |
Congratulation, now if you have successfully done as same in this, then, you can now successfully integrate Bootstrap NavBar 4 for your WordPress theme.
Output after you integrate Bootstrap NavBar 4 for your WordPress theme
Now, after you have successfully integrate Bootstrap NavBar 4 for your WordPress theme, then, you may like to know about how will it be displayed for your site, right? Well, we will make this clear for you too. You can see the similar result as below for your site too:
If you want to learn about how to assign the menu to particular menu location area provided via the theme, then, you can follow this link.
Conclusion
Now, if you have followed this tutorial properly and was able to integrate Bootstrap 4 NavBar into your WordPress theme properly, without any issue at all, then, we can assume that you are now more familiar about integrating it to your theme than before. But, if you are still confused on this and want more help on this, then, do drop the comment below in the comment box and we will follow it up.
Bài viết này thực hiện (hoặc lụm bài về đăng câu like từ các trang khác) bởi Việt Lâm Coder một YOUTUBER có tâm và đẹp trai siêu cấp vô địch zũ trụ. Các bạn đi ngang nếu được cho Lâm 1 like và 1 đăng ký kênh Youtube nhé !!