The ThemeShaper WordPress Theme Tutorial: 2nd Edition

Preface

Many of you have written or commented to tell us how much you liked Ian Stewart’s original tutorial, “How To Create a WordPress Theme: The Ultimate WordPress Theme Tutorial”. You’ll be happy to learn that that we’ve created a second edition of the tutorial! Just like last time, you can expect one new lesson each day. What’s changed in the second edition? Keep reading to find out!

What’s new in the Second Edition:

  • Updated code samples that draw from the Underscores (_s) starter theme. February 2012 marked the release of the Underscores (_s) starter theme, and since then, it has gathered plenty of momentum. The code samples and file structure for the theme we’re going to create in this tutorial will draw from _s as a source of modern code that reflects current best practices.
  • New Lessons. Developing Your Theme Sense is worth reading if you’re completely new to WordPress Theme Development. It’ll teach you what you need to know to sharpen your theme intuition. Setting Up Your Theme Functions guides you through creating an organized theme structure, and Secure your WordPress Theme tells you what you need to know to lock your theme down from potential security threats. Distributing Your WordPress Theme covers the steps you’ll need to take to prepare your theme for distribution, and what you need to know about licensing.
  • New Tools. We added new awesome tools to the Theme Development Tools lesson.

Introduction

In only 16 individual lessons, this WordPress Theme Tutorial is going to show you how to build a powerful, up-to-date, WordPress Theme from scratch. As we go along I’ll explain what’s happening including (for better or worse) my thinking on certain techniques and why I’m choosing one path over another. Essentially, I’ll be teaching you everything you need to know about WordPress Theme development.

At the end of this tutorial, you’ll be able to do almost anything you want.

The Theme Shaper WordPress Theme Tutorial: 2nd Edition

Skip to the Table of Contents.

Introducing the Underscores (_s) Starter Theme

If you haven’t heard of _s, in short, it’s a 100% GPL, community-driven starter theme that contains modern templates, starter CSS, and an organized file structure — everything you need to help you get your designs off the ground. You can also use _s as a starting point for your future theme projects. If you’d like to learn more about the thinking behind _s, please take a moment to read A 1000-Hour Head Start: Introducing the _s Theme. Come right back after you’ve read it. No, seriously, we’ll wait.

The simple theme we’re going to build in this tutorial, The Shape Theme (yes, it’s the  Shape Theme from the 1st Edition, updated for the 2nd Edition), is based on _s. Download it and check it out if you’d like to see the finished code we’ll be going through, live, in action. It’ll be a while before we get to the CSS lesson, but if you’d like to look ahead at the sample design we’ll eventually create for the Shape theme, you can grab it here.

A Word About Timeliness
Are you reading this on a date that makes October 2012 seem like a long time ago? Yes? Then there’s a good chance that some of the code samples in this tutorial are already outdated. That’s OK, because what’s more important is that you understand the broad concepts — the whys — that are presented in the lessons. You can always grab a copy of the latest _s source code from the GitHub repository.

Here’s the list of features your finished theme will be able to boast of:

  • A well-organized, modular file structure
  • All the search-engine optimization you’ll really need
  • Google-supported Microformat markup
  • Valid and logical semantic markup structure than can be used to create ANY layout
  • Smart default CSS layouts
  • Localization support: translation-ready mark-up and an RTL stylesheet
  • Dynamic body, post, and comment classes
  • Separated trackbacks and threaded comments
  • Two widget areas: the first one with default widgets, and the second coded to disappear when it’s empty
  • Support for the Aside Post Format (after the tutorial, you’ll easily be able to add support for more post formats)
  • A Custom Menu, Flexible Custom Header Image, and a Custom Background
  • Simple responsive styling, including a lightweight navigation menu for mobile devices
  • And all the typical WordPress stuff you expect from a theme

I think that’s kind of impressive—for any WordPress Theme.

WordPress Theme Tutorial Table of Contents

Ready for a WordPress Theme Tutorial that will show you how to create a powerful theme from scratch? Read it from the beginning and code yourself up something awesome. Note: if a lesson does not have an active link, it means that lesson hasn’t been published yet. :)

Check back every day for a new lesson.

  1. WordPress Theme Tutorial Introduction
  2. Developing Theme Sense
  3. Theme Development Tools
  4. Creating a Theme HTML Structure
  5. Template and Directory Structure
  6. Setting Up Your Theme Functions
  7. Secure Your WordPress Theme
  8. The Header Template
  9. The Index Template
  10. The Single Post, Post Attachment, & 404 Templates
  11. The Comments Template
  12. The Search Template & The Page Template
  13. The Archive Template
  14. The Sidebar Template & The Footer Template
  15. Reset-Rebuild Theme CSS & Define Your Layouts
  16. Custom Background & Custom Header
  17. Distributing Your WordPress Theme

Underscores.me — The Best Way To Get Started With The _s Theme

Back in February we introduced you to _s, or Underscores, the WordPress starter theme we use at Automattic to build the majority of our themes (and even when we’re not building themes from it we’re referring to it). It’s come a long way since then with a steady stream of refinements. But one thing about it has always been … less than refined. To fork _s you’d have to do a, well, OK, kind of annoying search and replace routine that could easily trip people up if they did it wrong. Thanks to the efforts of Hugo Baeta and Konstantin Kovshenin that isn’t the case anymore. And they’ve done away with that problem with incredible style. Themers, check out Underscores.me:

You can now download your own version of _s with your own custom theme name — the search and replace is all done for you. All you have to do is theme. Plus, you can see all the beautiful people who have contributed to your favorite WordPress starter theme. Look at them all! Community theme development, FTW.

So, what are you waiting for? Get over to Underscores.me and start developing that awesome theme. We can’t wait to see it.

Happy Anniversary, WordPress!

Everyone knows that we love WordPress Themes which means, of course, that we also love WordPress. But we don’t go around saying it everyday even though we do. With the 10th anniversary of WordPress around the corner of a team meetup in Italy the WordPress.com Theme Team had a chance to not just to say it but show it, in a way. Here we all are showing our WordPress pride in our 10th Anniversary WordPress shirts.

IMG_0051-(1)

Keep doing what you do WordPress and we’ll keep trying to make beautiful themes that do you justice. We’re looking forward to many more years of making it easy for anyone to publish on the web — and making it look amazing.

Five Minutes with Philip Arthur Moore

Did you know we have a Premium Theme Team at WordPress.com? They’re the folks who audit all of the premium themes available on WordPress.com — that’s not just the themes we make but also the ones made by other shops too — and make sure we have a consistently amazing experience with them. Philip Arthur Moore leads that team and there’s a great interview with him on the WordPress.com news blog.

The majority of my waking hours are spent feverishly obsessing over making premium themes a world-class experience for all WordPress users. This means a lot of different things: ensuring that customers are well-supported in our premium themes forum; auditing every single line of code in every premium theme; educating the WordPress theming community on proper approaches to WordPress theme development; and with my colleagues coming up with strong, robust guidelines for developing themes the WordPress.com way.

Philip also spends a ton of time working on _s. I love everything about this quote.

It’s hard to understand the power of _s unless you see what’s built with it. Further, Ryu, A Simpler Time, and Untitled were all created using _s, but you’d never know it without being told and that’s what makes the starter theme so powerful. To date, Underscores has around 34 total contributors and it’s always open to more. I’ll continue to work on it because it provides a solid benchmark on which to grade other themes and it also gives me a chance to interact with the theming community.

Anyway, quit reading this post and check out the interview with Philip.

Online Resources to Help You Learn All The Things

The web industry is always changing. Just when you get settled into a routine, the flow of technological innovations force you start a new one. Can you keep up? It never hurts to set aside some time for learning new skills and sharpening your current ones.

In this post, I’ll outline a few online resources that can help you continue your education in web design and development (or to get started, if you’re just joining us).

Continue reading

Validation and Sanitization in the Customizer

At Automattic, we exclusively use the Customizer for theme options instead of theme option pages. We believe that themes should only alter the display of content and should not add any additional functionality that would be better suited for a plugin. Since all options are presentation centered, they should all be controllable by the Customizer.

Continue reading

Behind the Design of the Ryu Theme

Much like I did for the Further theme, I’d like to share my thoughts behind Ryu — the free theme I released recently.

Yes, you guessed right. It’s named after the main character of the classic game. If you know why the character was named Ryu, you will understand why I named this theme Ryu, too. :)

I mentioned this in my previous post about the Further theme, Behind the Design of the Further Theme, too that I strongly believe that we, as WordPress theme designers, should create amazing themes for specific purposes/audiences rather than multi-purpose themes that are just good. In many cases, themes designed for a specific purpose or a targeted audience perform better when people use them for that purpose. I’ve created Ryu specifically for the Facebook, Tumblr, and Twitter generation of personal bloggers.

Continue reading

The Recipe for a Great Theme

Have you ever looked at a WordPress theme and thought, “Man, I wish I could do that!” Well, here’s a little secret: You totally can.

Yes, you can make a theme, and you don’t need to be a theme expert to do so. You just need three things:

  • An idea,
  • a healthy dose of curiosity,
  • and time.

An Idea

Until five years ago, I’d never touched a WordPress theme. I didn’t have a lot of experience, I’d never experimented with dynamic programming languages, and I’d never had to design for a vast and varied audience.

But what I did have were ideas – how about a theme for babies? Or a theme with changing seasons? Or a theme with animated fish? I didn’t know how to make these themes happen – I just knew I wanted to make them.

Without an idea, there is no theme! So before you do anything, figure out what you want to build. Have a goal to strive for, write up some notes, sketch it out.

It doesn’t have to be mind-blowing, or revolutionary, or the Next Big Thing, as long as you’re excited about it. You’re probably not going to make history with your first theme, but why let that deter you from making something really cool?

A Healthy Dose of Curiosity

If you like to learn, you’ve already taken a huge step toward becoming a themer. WordPress changes often, so theming techniques change often, too. You don’t have to venture far for learning material – you’re looking at a wealth of theme-makin’ goodness right here at ThemeShaper!

But I encourage you not to get mired in the technical details. You know how you may use Photoshop, but you probably don’t use one-tenth of its capabilities? Theming is like that. You don’t need to know how to do it all – you just need to figure out one piece at a time.

Think of your theme as a puzzle, and break it into smaller components – a fixed sidebar, an animated drop-down menu, a customizable header that changes colors – together they’re an intimidating obstacle, but if you tackle each piece individually, you’re likely to find it’s not as difficult as you think.

Also keep in mind, you don’t necessarily need to start from scratch (unless you want to!) Maybe you’re less interested in coding a theme, but you want to illustrate one – you can always build a child theme, or use a starter theme, so you don’t have to dive as deeply into the code.

Here are some of our favorite ThemeShaper resources to get you started:

And finally, tutorials have their place, but don’t be afraid to play around! Some of the best learning experiences and discoveries are hands on. Remember: There are very few things you could do to your WordPress theme that a quick Ctrl+Z can’t fix.

Time

We’ve come to the part I can’t help with. You have the idea, you have the tools, now you just have to make it happen. Easier said than done, but as they say, Rome wasn’t built in a day. Some of the best themes take weeks, months, or possibly even years, to come to fruition.

But beware: Theming is addictive. If you spend enough time with it, you may find yourself staying up late into the night to squash a CSS float bug, or research scripts for a post slider, or find just the right shade of blue for that navigation menu. Don’t say I didn’t warn you!

I hope this inspires you to give theming a chance if you haven’t already – it’s a great opportunity to try something new and make something cool!

The Line Between “Feature” and “Integral Part”

Last week, in light of the Evernote hack and a few others, I took the time to finally update all of my passwords to using 1Password. It’s a fantastic app that does its job very well, and I had tried it once before, but was turned off by the pop-ups, alerts, autosubmit, and the cluttered mess that auto-save created with my account (I’m OCD like that). Even though I needed to use the service, I tabled 1Password until I had “some time to get it setup correctly” (aka never, unless a security scare prompted me to).

I realize that this is similar to an issue that many newer users face in selecting themes. Often, users peruse new themes by their screenshots or demo sites, settle on one that’s especially appealing to them, and activate it only to find a stripped-out half-version of the theme due to unset (or too-set) options, missing content, page templates… the list goes on and on. I had always viewed those as first-world user problems – that people would complain about having too many options available or not having their complex site “just work” right out of the box – until I was faced with a similar issue and gave up without a second thought… and mine revolved around personal security, not a blog of pictures of my dog. :)

Hero demo site on WordPress.com vs. User theme activation

Hero demo site on WordPress.com vs. User theme activation

All of my complaints with 1Password were feature-related, not bug-related, which in particular resonated with me. A developer, or team of developers, had built these features, turned them on by default, and left them up to me to turn off. They’re cool features that I’m sure people like to use, but they’re not integral to the app, and they cluttered my new experience to the point that I walked away. This of course brought me back to something Takashi mentioned in his post about further, where one of our teammates, Philip Arthur Moore, compared theme options to a native app’s preferences and how a number of users probably never touch them:

“I wonder how many “normal” computer users start a program and never even look in the preferences page. It’s like, they open the program and that’s what they get… It makes me think themes out of the box should just work and theme options should be viewed like preferences sometimes… Food for thought.”

I’m not advocating the removal of special features from themes (or even screenshots) – I’m still a huge believer that these are some of the biggest selling points for users – I’m just wanting to keep the discussion going of where the line is between “feature” and “integral part”. It very likely shifts on a theme-by-theme basis (a banner image on Superhero, the homepage template on Responsive,  or just simply a first post in a theme like Minimalizine), and I think that there are probably a number of ways that we can make a theme either “just work” or better hold a new user’s hand through the setup of those integral parts. It’s easy to forget the first time we stepped inside the WordPress admin. I don’t know about you, but I’m comfortable saying that I was pretty lost. If making the web a more open place is ultimately our goal, I think encouraging the next generation of new users to stick with it as they start out is a great first step.