In WordPress, there are plenty of things we still don’t know. One of them is creating “multiple headers and footers” files and fetch their data.
Sounds new to you? Maybe!
Before I’m going to clear the thing, I assume you have a solid understanding of WordPress template system with header.php, footer.php and get_header(), get_footer() templates tags. Without knowing these, you’d not understand what I’m talking here.
Now, let’s describe the matter.
Every WordPress developer (theme developer actually) have to work on a lot of things in header and footer files to make the theme perfect. One of the main benefits of creating multiple headers and footers file is, the design looks unique for each page or a certain page you’d like to select in.
Suppose, your theme has a header (header.php) and a footer (footer.php) file –
header.php has 3 columns, containing a logo, menus, and social icons. footer.php has 2 columns, containing various links, text and subscription form for all the pages in your website. Now you want, except homepage, all other pages will have a design like so –
In the header, 2 columns with having only logo and social icon. And in the footer, 1 column with having copyright text.
So, you’ve to style a different header/footer file for your custom header/footer that will be added on the other pages except for home page as I said. You designed and named the new header/footer file to header-column-2.php or footer-full-width.php
Now, how could you call them to your theme? That, where you found WordPress’s beauty! 🙂
Just calling the normal get_header(); will fetch the data from header.php file. But if you call the get_header() with passing an argument like: get_header(‘column-2’); or for footer, get_footer(‘full-width’);. That will fetch the data from your custom made header (header-column-2.php) or footer (footer-full-width.php) file.
The thing to remember that, you must keep the prefix “header-“ and “footer-” before your custom header and footer file, and when you call them, call them without “header-“ or “footer-”. Otherwise, it won’t work!
So, if you’ve a file named new-style.php for header, name it to header-new-style.php and call it like get_header(‘new-style’);. So that, WordPress will automatically understand you’re asking data from the header-new-style.php file.
Sounds easy, huh?
Let’s share this article so that more peoples could know it.Views 577 times.