Blog Posts

Anatomy of a WordPress Theme

21 May Anatomy of a WordPress Theme

When you go to appearance > editor, you’ll notice there are a list of files on the right hand side that you can edit for any given theme. Some themes have a lot, while others have but two. Most themes have anywhere from 15-50 theme files. The basic way WordPress works is like this: there are dozens and dozens of files, but only theme files can be modified. Core files (the other files that make up WordPress) shouldn’t ever be changed.

That’s why updating WordPress works the way it does. Your content is never touched, and only the core files are changed.

Each theme needs but two files: style.css and index.php. All the rest is icing on the cake. But, most themes, will have some other basics: single.php, page.php, home.php, header.php, footer.php, sidebar.php, functions.php, comments.php, 404.php and even more.

Lets take a look at each:

  • style.css – traditionally, this has been the file to hold all the CSS for themes. We’re seeing a trend of responsive themes, which means more and more styles, and stylesheets. Which means more and more separation (responsive styles vs. regular styles). Style.css also holds all the theme info (name, author, version, etc.)
  • index.php – this is the fallback template for all content. Theoretically, you could display all your content via index.php just using a bunch of different conditional tags. Obviously, it’s easier to read, edit and maintain if everything is broken up.
  • single.php – this is the template for a single blog post. This post is being displayed with the single.php template.
  • page.php – this is the template for a single page.
  • page-{templatename}.php – this is the template for a different page. Traditionally something like page-fullwidth.php would be similar to page.php but without any sidebars. There can be unlimited page templates, and you’ll notice when you’re editing a page, you can select the template on the right hand side.
  • home.php – this is the template for the front page of your site. It will fall back to the index.php. To make your site have a page that you’ve created go to settings > reading and change the front page. Then the front page will pull from the page template of the page you’ve set.
  • header.php – this is the template for all header info. Usually includes navigation as well.
  • footer.php – this is the template for all footer info.
  • sidebar.php – this is the template for the sidebar of your site. Using get_sidebar() in the other templates, will just pull in this file.
  • functions.php – this is where all your theme functions live.
  • comments.php – this is the comments template.
  • 404.php – this is the template that is displayed when a URL can’t be resolved. Thus: is displaying the 404.php template.

There can be a lot more files included in themes, but those are the main ones. Also, themes should be edited using child themes, so when the actual theme has an update, it can be seamlessly updated without any headache.

No Comments

Leave a Reply