menu

How To Add Header and Footer In WordPress Page

Spread the love

Today we will see how to add header and footer in WordPress page. In WordPress custom theme today we will look at two functions to add header and footer.
To call it you have to put the code in header in header.php and footer in footer.php

To show the header and footer, it is necessary to use the following function.

 <?php get_header() ?>

 <?php get_footer() ?>

By going to index.php, from the beginning of the HTML to the end of the navigation, cut it from there and paste it in the header.php and write ( <?php get_header() ?> ) function in the index.php file.

In this way the footer starts from that to the html close, cut the code of that and paste it in footer.php and write this function in index.php ( <?php get_footer() ?> ).

get_header and get_footer are only meant to work in wordpress it will not work in any other framework.
You need to create a proper header.php file to call get_header
You need to create a proper footer.php file to call get_footer

To add multiple headers in WordPress you need to create header-headername.php file and you have to call that header <?php get_header(‘headername’); ?> function has to be used.

 <?php get_header('headername'); ?>

In this way we can create multiple header.

To add multiple footer in WordPress you need to create footer-footername.php file and you have to call that footer <?php get_header(‘footername’); ?> function has to be used.

<?php get_footer('footername'); ?> 

In this way we can create multiple footer.

How to Register Nav Menu in WordPress Custom Theme?

To register nav menu in WordPress custom theme, you have to use the function with the help of which you can bring menu in admin and can also show on website.

The nav menu will not be registered in the WordPress custom theme, until then the menu will not show in the back end of WordPress, so first you have to get the menu show in the WordPress custom theme, for that you will have to write a function.

Before

To register nav menu in WordPress custom theme, you have to create a function by going to functions.php file which is mentioned below

<?php 

register_nav_menus(
	array('primary-menu' => 'TOP MENU')
);

?> 

After

In WordPress custom theme, the menu has come in the back end, now you have to do another function used to bring the menu in the website.

The name given in register_nav_menus in the menu bar it will show on

Before that you have to create 4 – 5 pages then we will show it in dynamic menu with the help of while loop.

Add the new pages that you have created in the top menu, now you have to use wp_nav_menu function in header.php

<?php 
wp_nav_menu(array('
theme_location'=>'primary-menu'));
?>

If you do that function in header.php, then you will start showing menu on the website but you will have to custom design it.

Before

wp_nav_menu will give us the design of the ul.li menu now we will add one more parameter to the menu function and add the class name to it.

<?php 
wp_nav_menu(array('
theme_location'=>'primary-menu','menu_class'=>'nav'))
?>

then we are use some custom CSS style


.nav{
display: flex; 
}
.nav li{
margin: 0 30px;
}
.nav li a{
color: #000;
}

After


Spread the love

Related Posts

Leave a Reply

Your email address will not be published.