Headers and footers are the top and bottom parts of a website. Customizing them helps make your site look unique and easy to use.
Header and footer customization in Wordpress
Start learning this pattern below
Jump into concepts and practice - no test required
or
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Introduction
Syntax
Wordpress
<?php // To customize header get_header(); // To customize footer get_footer(); ?>
Use get_header() to include the header template.
Use get_footer() to include the footer template.
Examples
Wordpress
<?php // Basic header call get_header(); ?>
Wordpress
<?php // Load a custom header named 'custom' get_header('custom'); ?>
Wordpress
<?php // Basic footer call get_footer(); ?>
Wordpress
<?php // Load a custom footer named 'special' get_footer('special'); ?>
Sample Program
This WordPress template loads the default header and footer around the main content. You can create custom header.php or footer.php files to change their look.
Wordpress
<?php /* Template Name: Custom Header Footer Example */ get_header(); ?> <main> <h1>Welcome to My Custom Page</h1> <p>This page uses a custom header and footer.</p> </main> <?php get_footer(); ?>
Important Notes
Always back up your theme files before editing header or footer.
Use child themes to keep your changes safe during updates.
Check your site on mobile to make sure header and footer look good everywhere.
Summary
Headers and footers are key parts of your website layout.
Use get_header() and get_footer() to add them in templates.
Custom header and footer files let you change the look and content easily.
Practice
1. What is the main purpose of using
get_header() and get_footer() functions in a WordPress theme?easy
Solution
Step 1: Understand the role of
These functions load the header.php and footer.php template files into the current page template.get_header()andget_footer()Step 2: Identify their purpose in theme structure
They help keep the header and footer code separate and reusable across pages.Final Answer:
To include the header and footer template files in a theme's page -> Option DQuick Check:
Include header/footer = A [OK]
Hint: Remember: get_header() loads header.php, get_footer() loads footer.php [OK]
Common Mistakes:
- Thinking these functions add CSS styles
- Confusing with menu registration functions
- Assuming they remove sections instead of adding
2. Which of the following is the correct way to include a custom header file named
header-special.php in a WordPress theme template?easy
Solution
Step 1: Recall how to load custom header files
WordPress usesget_header('name')to loadheader-name.php.Step 2: Match the function to the file name
Forheader-special.php, callget_header('special').Final Answer:
get_header('special'); -> Option BQuick Check:
Custom header call = B [OK]
Hint: Use get_header('name') to load header-name.php files [OK]
Common Mistakes:
- Using include() instead of get_header()
- Confusing get_template_part() with get_header()
- Using non-existent functions like load_header()
3. Consider this WordPress theme template snippet:
What will be the output on the webpage if
<?php get_header(); ?> <main>Content here</main> <?php get_footer(); ?>
What will be the output on the webpage if
header.php contains a <header> with "Welcome" text and footer.php contains a <footer> with "Goodbye" text?medium
Solution
Step 1: Understand what get_header() and get_footer() do
They insert the contents of header.php and footer.php respectively into the page.Step 2: Combine the template parts
The page will display the header content "Welcome", then the main content, then the footer content "Goodbye".Final Answer:
The page will show a header with "Welcome", main content, and a footer with "Goodbye" -> Option CQuick Check:
Header + main + footer = D [OK]
Hint: get_header() and get_footer() add their files' content around main [OK]
Common Mistakes:
- Thinking main content is replaced or ignored
- Assuming parameters are required for these functions
- Expecting an error without parameters
4. You added
get_footer('custom'); in your theme template, but the footer does not appear and the page shows an error. What is the most likely cause?medium
Solution
Step 1: Understand how get_footer('name') works
It tries to loadfooter-name.phpfrom the theme folder.Step 2: Identify the cause of error
Iffooter-custom.phpis missing, WordPress cannot find the file and throws an error.Final Answer:
The file footer-custom.php does not exist in the theme folder -> Option AQuick Check:
Missing footer-custom.php = A [OK]
Hint: Check if footer-custom.php file exists before calling get_footer('custom') [OK]
Common Mistakes:
- Thinking parameters are not allowed in get_footer()
- Assuming registration is needed for custom footers
- Ignoring missing file errors
5. You want to create a WordPress theme where the header shows a different logo on the homepage and another logo on all other pages. Which is the best way to customize the header for this?
hard
Solution
Step 1: Understand conditional header loading
WordPress allows loading different header files usingget_header('name').Step 2: Apply conditional logic in template
Use PHP to check if it is the homepage, then callget_header('home'), elseget_header().Step 3: Organize header files
Createheader-home.phpwith the homepage logo andheader.phpwith the default logo.Final Answer:
Create two header files: header-home.php and header.php, then use get_header() or get_header('home') conditionally -> Option AQuick Check:
Conditional header files = C [OK]
Hint: Use get_header('home') for homepage, get_header() for others [OK]
Common Mistakes:
- Trying to swap logos only with CSS or JavaScript
- Putting logos in footer instead of header
- Not using conditional PHP logic for headers
