When learning custom WordPress theme development, one of the most exciting parts is creating reusable theme features like sidebars, menus, archive pages, and footer areas.
Today, I learned:
- How to create sidebars in a WordPress theme
- How to create a footer in a WordPress theme
- How to create archive files
- How to use
get_template_part() - How to add menus in the header and footer
In this blog post, I’ll explain these concepts in a simple and beginner-friendly way.
1. How to Create Sidebars in a WordPress Theme
A sidebar is an area where we can add widgets like:
- Recent Posts
- Categories
- Search Bar
- Custom Text
Step 1: Register Sidebar
Open your functions.php file and add:
function mytheme_sidebar() {
register_sidebar(array(
'name' => 'Main Sidebar',
'id' => 'main-sidebar',
'description' => 'This is the main sidebar area',
'before_widget' => '<div class="sidebar-widget">',
'after_widget' => '</div>',
'before_title' => '<h3>',
'after_title' => '</h3>',
));
}
add_action('widgets_init', 'mytheme_sidebar');
Step 2: Display Sidebar
Create a file called:
sidebar.php
Add this code:
<?php dynamic_sidebar('main-sidebar'); ?>
Step 3: Load Sidebar in Theme
Use this code where you want the sidebar:
<?php get_sidebar(); ?>
Now your sidebar is ready.
2. How to Create Footer in WordPress Theme
The footer is the bottom section of a website.
Usually it contains:
- Copyright text
- Footer menu
- Social links
- Widgets
Step 1: Create footer.php
Create:
footer.php
Add:
<footer class="site-footer">
<p>© <?php echo date('Y'); ?> My Website</p>
</footer>
<?php wp_footer(); ?>
</body>
</html>
Step 2: Load Footer
Use this code inside theme files:
<?php get_footer(); ?>
This helps keep the footer reusable across all pages.
3. How to Create Archive File in WordPress Theme
Archive pages show grouped posts like:
- Category posts
- Tag posts
- Author posts
- Date posts
Step 1: Create archive.php
Create:
archive.php
Step 2: Add Loop
<?php get_header(); ?>
<h1><?php the_archive_title(); ?></h1>
<?php if(have_posts()) : ?>
<?php while(have_posts()) : the_post(); ?>
<h2><?php the_title(); ?></h2>
<p><?php the_excerpt(); ?></p>
<?php endwhile; ?>
<?php else : ?>
<p>No posts found.</p>
<?php endif; ?>
<?php get_footer(); ?>
Now WordPress will automatically use this file for archive pages.
4. Use of get_template_part()
get_template_part() helps us reuse code in multiple places.
Instead of writing the same code again and again, we can separate small template files.
This keeps the theme clean and organized.
Example
Create folder:
template-parts
Create file:
template-parts/content.php
Add:
<article>
<h2><?php the_title(); ?></h2>
<p><?php the_excerpt(); ?></p>
</article>
Load Template Part
Inside archive.php:
<?php get_template_part('template-parts/content'); ?>
This is very useful in professional theme development.
5. How to Add Menus in Header & Footer
Menus help users navigate the website.
Step 1: Register Menus
Inside functions.php:
function mytheme_menus() {
register_nav_menus(array(
'primary-menu' => 'Primary Header Menu',
'footer-menu' => 'Footer Menu',
));
}
add_action('after_setup_theme', 'mytheme_menus');
Step 2: Display Header Menu
Inside header.php:
<?php
wp_nav_menu(array(
'theme_location' => 'primary-menu',
));
?>
Step 3: Display Footer Menu
Inside footer.php:
<?php
wp_nav_menu(array(
'theme_location' => 'footer-menu',
));
?>
Now you can manage menus from:
Dashboard → Appearance → Menus
What I Learned Today
Today I learned some important concepts of WordPress theme development:
- Creating dynamic sidebars
- Building reusable footer files
- Making archive templates
- Using
get_template_part()for clean code - Adding navigation menus in header and footer
These features help create a professional and flexible WordPress theme.
Final Thoughts
Learning custom WordPress theme development becomes easier when we practice small features step by step.
At first, files like archive.php, sidebar.php, and footer.php may feel confusing, but after some practice they become simple.
The best way to learn is:
- Create files yourself
- Test code regularly
- Break large tasks into smaller parts
Slowly, you will understand how WordPress themes work internally.
Happy Coding 🚀
