Now that you’ve already learned how to set up a theme, you’ll need to learn how to structure a theme.
If you haven’t already done so, you need to read through the earlier posts in this tutorial series to do some catching up. From this point forward, you’ll be expected to know the lessons taught in previous tutorials.
Basic template structure
Most WordPress themes will have a few basic templates that define the overall structure of the theme:
index.phpheader.phpfooter.phpsidebar.php
The following screenshot shows a simple overview of what these templates might look like in a finished theme design.

What are templates?
The term “template” can be a bit confusing, especially since it’s easily interchangeable with the terms “theme” and “skin.” In WordPress it means something different. A template in WordPress is a PHP file that is used for the display of content on the front end of the site.
For those of you familiar with creating HTML Web pages, you’re probably accustomed to creating a single HTML file and having it display all of the content on the page. In WordPress, each part of the page is broken into separate sections. The reason for this is that WordPress is a dynamic system, which runs an entire Web site rather than just a single page.
Having the templates separated allows you to re-use templates across different page views. For example, the header.php file contains all of the content the header of a site would display. Instead of creating many files with the same header information over and over, you can use a single file (template) to display this information on all pages.
index.php
The index.php template is the default template for displaying content (blog posts, pages, etc.) on a site. There are other files that can overwrite it, but you’ll learn about those in a later tutorial. For now, you’ll learn about its most important function: holding everything together.
When any page on a WordPress site is loaded, it looks for a template. In our case, this is the index.php template. It will be the template that’s expected to display the page.
In part 1 of this tutorial series, you created an empty index.php file. You need to open this file in your text editor. Type the following code in this file.
<?php get_header(); // Load the header.php template. ?>
<div id="content">
</div><!-- #content -->
<?php get_footer(); // Load the footer.php template. ?>
This code does several things:
- Uses the WordPress function get_header() to load the
header.phptemplate. - Defines some basic HTML for the structure of our future content.
- Uses the WordPress function get_footer() to load the
footer.phptemplate.
Don’t worry if you don’t understand those PHP functions. You’ll learn more about them in the next tutorials.
header.php
In the previous section, you used a PHP function called get_header() to load a template called header.php. Since this file doesn’t exist yet, you’ll need to create it. So, create a new file using your text editor called header.php and save it within your theme folder.
Remember, your theme folder’s name is super-mario, so the files in your theme should look like the following at this point.
super-marioheader.phpindex.phpstyle.css
Once you’ve created your header.php template, type the following code into it.
<!DOCTYPE html>
<html>
<head>
<title>Example</title>
<link rel="stylesheet" href="style.css" type="text/css" media="all" />
</head>
<body class="wordpress">
<div id="container">
<div id="header">
</div><!-- #header -->
<div id="main">
What the preceding code does is define a simple HTML structure for your header. Those of you familiar with basic Web pages and HTML, this should look familiar to you. There’s no PHP code involved at all at this point for the header. You’ll learn about that later.
footer.php
The footer template should close out all open HTML tags that were opened in the header template.
In the index.php section of this tutorial, you used the get_footer() function to load the footer.php template. Just as you did with the header template, create a new file with your text editor called footer.php and place it within your theme folder.
Now, type the following code into the file.
<?php get_sidebar(); // Load the sidebar.php template. ?>
</div><!-- #main -->
<div id="footer">
</div><!-- #footer -->
</div><!-- #container -->
</body>
</html>
As you can see, these are mostly all closing HTML tags. You probably also noticed the PHP function call to get_sidebar(), which is a WordPress function for loading the sidebar.php template.
sidebar.php
A sidebar is a template in WordPress for displaying content in addition to the main page content. For now, you’ll just be building the basic HTML structure for a single sidebar.
Once again, crack open your favorite text editor. This time, create a new file called sidebar.php and place it within your theme folder alongside your new header.php and footer.php templates.
Type the following code in your sidebar.php template.
<div id="sidebar">
</div><!-- #sidebar -->
When do we get to the good stuff?
I know. I know. You’re really itching to make your theme actually do something. Remember, you need to learn to crawl before you can walk. It’s better to learn how some of the basic functionality comes together before you dive head first into more advanced things. You’ll get lost later without a solid foundation to build from.
In the next three tutorials, you’ll learn how to make your header.php, footer.php, and index.php templates display content from WordPress, so get ready. This tutorial series is about to get a little more complex. Therefore, you should feel good in knowing that you’re learning the basics now.
Downloads
If you want to see all of today’s lesson files, download a zip file of the theme. This version builds on the version from the previous tutorial, so there’ll be files included from that lesson too.
I’m loving this series! Keep it up Justin. Great stuff… Thanks!
Thanks Justin. I’m looking forward to the next one.
Nice and simple explanation. A video primer would be a good option to teach wordpress theme building. Not very much people think of making themes by themselves.
Will wait for the next post
did you decide against using HTML5?
The code in the tutorial is HTML5.
I think what Paul might be referring to is your avoiding the use of the new HTML5 elements such as “header”, “footer”, “section”, “article”, and the like.
Oh, yeah, I’m intentionally avoiding using new elements like those.
ok but why? the WordPress theme team are using them
Mostly, just because I don’t want to use those elements just yet. Another reason would be familiarity for the reader of these tutorials. It’s easier to avoid having to teach entirely new HTML elements to folks who might have just spent some time learning HTML and aren’t familiar with the new stuff. Plus, some people learning have probably already looked at a few themes and not recognize those elements.
If you know enough about the new elements in HTML5, then by all means, use those elements. Remember, this is a tutorial series for a complete noob to theme development. A discussion on whether to use new HTML5 elements is largely irrelevant.
I assume you meant WordPress.com (Automattic) theme team. There’s no WordPress theme team.
Makes sense to me Justin, and I agree.
What are your thoughts on moving to using ID’s/classes that match and mimic the naming conventions of the new HTML5 elements? You have most of them here already (id=”header”, id=”footer”, etc.), what are your thoughts on moving towards using matching ID’s and classes in totality, or do you think it is best till HTML5 moves closer to the Candidate/Proposed Recommendation phase?
yes, I meant Ian Stewart and team at Themeshaper.com.
Chris, I’m in favor of using that type of system. For me, I just try to use IDs/classes that are relevant to the type of data they hold.
The code I’m using above and will be using throughout this tutorial is a fairly basic (and flexible) HTML structure that we’re using both here at DevPress and in other places. A large majority of it is something I’ve developed and settled on over the past few years. When the DevPress team got together, we came up with a few rules to follow for certain things, which I’ll be getting to in later tutorials.
When developing themes, I often find that folks learn a single method to start with but begin building their own, unique systems as they become more advanced. The HTML used in the tutorials will just be a jumping off point.
I really appreciate these tutorials. I hope that you will go through the basic stuff added under the appearance menu, menus and widgets, and maybe even header images, backgrounds and some basic theme options. It would also be great to maybe add a page template and/or post format.
I’ll definitely be covering all those things in later tutorials.
Great news there. I love how simple you are starting. All of that stuff is great! If you throw in a slider and a portfolio custom post type, we will have the features of about half the themes released on a certain marketplace.
Hi Justin, I like this simple and clear tutorial series.
Just a question, why do you include the sidebar in the footer template instead of in the index.php?
index.phpis a default template. Nearly all themes will have more specific templates that will overwrite it. Therefore, those templates would also need to include the sidebar. It makes more sense to add it once infooter.phprather than putting it in multiple templates.Tung mentioned the other day that I’m a “lazy programmer,” but I think that comes with the job description. Developers are always looking for ways of streamlining or simplifying their code (basically creating less work in the future). It’s a cornerstone of smart development practice.
yea…
i never think about this..
the only reason i put sidebar in index and archive is because full width page template, so i can just delete that in full width page template.
but, wordpress have is_page_template.
you’re lazy genius.
There are even cooler things you can do than that too. I’ll cover it when I dive into sidebars in more depth, but WordPress has a hook called
sidebars_widgetsthat’s extremely useful for that sort of thing.wow, i did a little search, i hope it’s about
http://justintadlock.com/archives/2009/03/06/disable-widget-areas-without-touching-theme-templates
i did a mess my theme, i ussually just create a lot of template for everything just because of sidebar/widget area.
more like carrington theme, which i think really speed up my developement time.
but this is really cool.
Yep, that’s mainly what I was referring to.
Thank you for this great series! I’m anxious for the next lesson. When can we expect it?
Great tutorials so far! Definitely looking forward to delving in to the tutorials for the other templates files once posted.
Hoping you cover some topics other tutorials don’t (like having 2 sidebars, hanging dates, and ability to change headers and backgrounds in the admin).
wow, talk about good timing!
A few years ago, I stumbled onto Tung’s “So you want to create WordPress themes” series. It was the most helpful, easy-to-read instructions I had found. I’m just in the process of “relearning” things, and found this new series.
Thank you! Thank you for taking the time to re-write this tutorial, bringing things up to date.
Can’t wait for the next post!
I am re-considering my stance on always using a child theme, because it seems with creating a child theme I spend way, way too much time on over riding functionality and styling from the parent theme. Now, I am thinking I can just role my own theme. Thanks for giving me the tools to do just that with this tutorial series.
Any idea when you’ll be posting the next tutorial in this series, Justin? Would really love to see it soon!
Sorry, I got a little behind on writing this. I’ve had a lot of work over the past few weeks. I plan to continue the series next week though.
Awesome!
Can’t wait! When you do post the next tutorial, will you PLEASE also post a comment here so that we’ll get emails to alert us? Thanks Justin!
Justin, I can’t wait to dive into your next tutorial. I know it goes a bit slower for me too, but I have only a few habits to know how to read php code and to modify it for my needs, but what I need to learn is how to write down my own code for all my needs instead of searching somebody to do the job so that I can redo it.
the 5$ donations is really nothing about your precious advices I have used even before on your ThemeHybrid site. And I do like your simplicity too as I have found thousands of themes and/or plugins that are literally eating the CPU and cause tons of problems so now I need some more control over the CPU usage of my themes as well as the SEO matter.
Thanks again and l am signing to join the club
Waiting for your next tutorial!
great work,and a really thanks
I cant wait for the next tutorial. This has been easy for me to follow
+1 Amy’s comment – or is there an RSS feed or for this series of tutorials?
And I know you’re aiming at complete beginners at theme design (like me), but I don’t think it would hurt to make them a little ‘chunkier’. Anyone who’s looking at developing themes is likely to have some basic understanding.
(that’s another way of saying I’m impatient for the next one!
I would just subscribe to the RSS feed for the main site… it’s well worth it in my opinion.
+1 This is great. An up to date, best practices WordPress tutorial! I stumbled upon your site, and 15 other related ones, because I was looking for a solution to putting facebook connect button in my comments. I did go through the Themeshaper tutorial (might not have completed it) about 6 months ago, but it was hard for me to understand. Since then I’ve been on a crash course to Wordpress, and have decided that WordPress is what I’m going to specialize in (I think). I have a few clients, and they are throwing all kinds of stuff at me. I have been able to handle everything, but sometimes it’s challenging.
Although much of what has been already posted is “muy” simple, it sounds like you are going to go into depth on a lot of important topics that I am really interested in. Nevertheless, I’m glad you’re taking the simple detailed route, because I’m sure it won’t be long before you get way over my head, and I’ll need you to go slow.
Thanks much
Hi Justin,
Thanks for creating this tutorial. I´m just getting started with Wordpress templates and to be honest I feel quite lost.
I´m not new to HTML but I´m not an expert either. I think what puzzles me the most is working out how to put a menu (the usual HTML website type of menu) because most of the templates I´ve found use post, pages and categories in the template and one of my blogs is just growing too much in content that I need to break it down into sections that can be reached from every page on my blog.
The tutorial is quite useful in starting to understand how the different elements of a wordpress template fit together.
I look forward to the next lesson and maybe I´ll learn how to edit my current template to put the menus in and assign different pages to different menu options.
Thanks again!
I like this tutorial …. i am planning to implement it with html5
While I’m not trying to design my own themes, I do like to change existing ones up a little to suit my needs. So it’s still helpful to learn some basics of HTML. Thanks!
Nice theme building tutorial you have here. Awesomely nice of you man. Thanks for this.
Justin it is very nice, simply explained. keep going……
Just discovered these tutorials. They’re excellent. You write well and explain things clearly. Really hope you can find the time to continue them!
Hi Justin, did you ever finish this tutorial series? If so, where can I find the remainder of the lessons?
Thanks!