Register Navigation to WordPress Theme

In this article, We will Register Navigation to WordPress Theme. In the previous article, we learned about how to link style and bootstrap CSS file. We will register navigation to WordPress theme. Before reading this article, you should know the basic of PHP programming. WordPress is build up using HTML, CSS, and PHP. So you should know basic about this languages.

Register Navigation to WordPress ThemeYou also have a basic knowledge of bootstrap because we are using bootstrap to build a WordPress theme. When you want to customize your navigation WordPress gives you an option to customize it. But this option is available only when you register a navigation.

So in the function.php file, you can register a navigation. We are registering navigation in function.php file and then specify the location where you want to show this navigation. In this article, We will register navigation and also register footer navigation.

Following is the code will register header and footer navigation. Place this code inside functions.php file.

Here we declare a function called register_navigation. In that function, we called register_nav_menus function and pass an array. This array content three navigation. primary, secondary and footer. You can create multiple navigations as per your requirement.

In the array, we specify the name of the navigation and then specify text label which user see in the WordPress menus.

In the end, we will call a function add_action. This function will call the register_navigation function when WordPress site load. In the add_action function, we will specify init which is called after WordPress has finished loading and the name of the function which we wanted to call.

Specify Navigation Location

Now we want to specify a location for the header and footer. So we will go back to the header and in the nav tag, we will insert the code which called primary menu.

In this code, we used wp_nav_menu to called primary menu. wp_nav_menu function will take an array. Array content the location of the primary menu. You can call multiple navigations on the same location also.

After that, We want to put this code in the footer also. So we will go to footer.php file and insert this code.

This is the same function we call for the header. Here we call footer navigation.

Before running your website make sure you specify navigation for your theme and also check the box of primary menu and footer menu.

If you have any questions then comment me on the bottom of the page.

In the next article, we will create the style for this navigation and create bootstrap responsive navigation. We will see you in the next article.

Thank You.