📖 Scenario: You are building a simple WordPress theme for a local bakery website. The bakery wants a custom header with their logo and navigation menu, and a custom footer with contact info and social media links.
🎯 Goal: Create a WordPress theme with a custom header and footer using header.php and footer.php files. The header should include the bakery's logo and a navigation menu. The footer should include contact information and social media links.
📋 What You'll Learn
Create a header.php file with a logo image and a navigation menu using wp_nav_menu().
Create a footer.php file with contact information and social media links.
Use WordPress functions get_header() and get_footer() in the main template file index.php.
Ensure semantic HTML5 structure with <header> and <footer> tags.
💡 Why This Matters
🌍 Real World
Custom headers and footers are essential for branding and navigation in WordPress websites. This project shows how to build them properly in a theme.
💼 Career
Knowing how to create and customize headers and footers is a key skill for WordPress theme developers and web designers.
Progress0 / 4 steps
1
Create the header.php file with logo and navigation menu
Create a file called header.php that contains a <header> element. Inside it, add an <img> tag with src="/wp-content/themes/your-theme/images/logo.png" and alt="Bakery Logo". Below the image, add a navigation menu using wp_nav_menu() with the argument array('theme_location' => 'primary').
Wordpress
Hint
Use the <header> tag for the header section. Use wp_nav_menu() to display the menu registered as 'primary'.
2
Create the footer.php file with contact info and social links
Create a file called footer.php that contains a <footer> element. Inside it, add a paragraph with the text Contact us at: info@bakery.com. Below that, add an unordered list with three list items containing links to Facebook, Twitter, and Instagram with hrefs https://facebook.com/bakery, https://twitter.com/bakery, and https://instagram.com/bakery respectively.
Wordpress
Hint
Use the <footer> tag for the footer section. Add contact info in a paragraph and social links in a list.
3
Use get_header() and get_footer() in index.php
In the index.php file, add the PHP function calls get_header(); at the top and get_footer(); at the bottom to include the header and footer templates.
Wordpress
Hint
Use get_header(); to include the header and get_footer(); to include the footer in your main template.
4
Add semantic HTML5 structure and register the menu
In your theme's functions.php file, register a navigation menu with the location name 'primary' using register_nav_menus(). Also, ensure your header.php and footer.php use semantic HTML5 tags <header> and <footer> respectively.
Wordpress
Hint
Use register_nav_menus() inside a function hooked to after_setup_theme to register your menu location.
Practice
(1/5)
1. What is the main purpose of using wp_head and wp_footer hooks in WordPress?
easy
A. To change the site's main menu items
B. To add custom content or scripts to the header and footer sections of a site
C. To create new pages in WordPress
D. To delete default WordPress themes
Solution
Step 1: Understand the role of hooks
Hooks like wp_head and wp_footer allow adding extra code to header and footer areas.
Step 2: Identify their use
They are used to insert custom HTML, CSS, or JavaScript in those sections without editing theme files directly.
Final Answer:
To add custom content or scripts to the header and footer sections of a site -> Option B
Quick Check:
wp_head and wp_footer add content to header/footer [OK]
Hint: Remember hooks add code to header/footer areas [OK]
Common Mistakes:
Thinking hooks create pages
Confusing hooks with menu settings
Assuming hooks delete themes
2. Which of the following is the correct way to add a custom script to the footer using wp_footer hook in your theme's functions.php?
easy
A. add_action('wp_footer', function() { echo ''; });
B. add_action('wp_head', function() { echo ''; });
C. add_filter('wp_footer', function() { echo ''; });
D. add_action('footer', function() { echo ''; });
Solution
Step 1: Identify correct hook and function
The wp_footer hook is used with add_action to add code to the footer.
Step 2: Check syntax correctness
add_action('wp_footer', function() { echo ''; }); uses add_action('wp_footer', function() { ... }); which is correct syntax to add inline script.
Final Answer:
add_action('wp_footer', function() { echo '<script>alert("Hi")</script>'; }); -> Option A
Quick Check:
Use add_action with wp_footer for footer scripts [OK]
Hint: Use add_action with wp_footer to add footer code [OK]
Common Mistakes:
Using add_filter instead of add_action
Using wp_head instead of wp_footer for footer scripts
5. You want to add a custom header message only on the homepage and a footer copyright notice on all pages. Which is the best way to do this in your theme's functions.php?
hard
A. Use add_filter instead of add_action for both hooks
B. Add both messages inside wp_footer hook without conditions