There sure is a lot you need to remember when working with WordPress theme files.
From the names of basic template files to functions and how the WordPress Loop works, it’s next to impossible to remember every PHP tag or even how to define a new theme.
About 550 students enrolled in our Academy course, WordPress Development for Beginners, are in their final week, all tackling the final assignment – building a WordPress theme from scratch.
So to help you out, I thought I’d put together this handy cheat sheet, which includes all the files and functions you need to know (but not necessarily remember!) when working with themes. This is definitely one to bookmark and save for future reference!
Good luck with your final assignment, and if you’re not already enrolled in WordPress Development for Intermediate Users, get in quick before enrollments close soon!
Theme Files
These are the basic files that every theme should include:
style.css
– This is your theme’s stylesheet file.index.php
– This is the main body template for your theme. Its job is to bring together all the information in the other theme files using template tags.header.php
– This file contains the header information that appears with thesection of your site, stuff like metadata and the link to your stylesheet.
sidebar.php
– Everything in you sidebar goes in this file, like widgets, categories, additional menus, search form, etc.footer.php
– This file contains your footer information, such as copyright details, widgets, and social icons.single.php
– This file displays just one post.page.php
– When you create a page on your site, this is the template responsible.comments.php
– This file is responsible for displaying comments.404.php
– When visitors try to visit a page on your site that doesn’t exist, this file will general an error page.functions.php
– This file is where you can place special functions. We always recommend creating a child theme rather than edit this file directly.archive.php
– Display an archive with this file so visitors to your site can go way back when and read your Hello World! post.search.php
– Help your visitors search your site with this page.searchform.php
– Display a search form for your visitors with this template file.
Defining a New Theme
Your stylesheet doesn’t just contain styling information for your theme – it also holds details about your theme that are displayed in the Appearance > Themes section of your WordPress admin.
The following is an example of the first few lines of the stylesheet for the default Twenty Sixteen theme:
.gist table { margin-bottom: 0; }
This information goes at the top of your stylesheet.css file.
Template Include Tags
Template include tags are used within one template file (for example index.php) to include (or call) the HTML and PHP found in another template file (for example header.php). While PHP has its own built-in include() statement to do this, these WordPress-specific tags make life much easier:
– Includes the header.php file
– Includes the sidebar.php file
– Includes the footer.php file
– Includes your comments
Template Header/Bloginfo Tags
These are functions you’ll find in your theme’s header.php file, though you’ll also find them in other theme files:
– The title of your site, or blog name
– Your site’s URL
– Link to your themes’s stylesheet file
– Location of your site’s theme file
– Displays the tagline of your blog as set in Settings > General.
– Link to your site’s atom URL
– RSS feed URL for your site
– Pingback URL for your site
– WordPress version number
– The HTML version your site is using
– The root URL for your site
– Location of your stylesheet folder
– Title of a specific page
Template Tags
These tags can be used across all of your template files, such as index.php or page.php, making it easy to display specific information anywhere you want on your site:
– Displays the content of a post
– Displays the excerpt used in posts
– Title of the specific post
– Link of a specific post
– Category of a specific post
– Author of a specific post
– ID of a specific post
– Edit link for a post
– URL of the next page
– URL of the previous page
– Lists all links in blogroll
– Lists all pages
– List archive for the site
– Lists all categories
– Displays the built-in calendar
– Displays register link
– Displays login/logout link only to registered users
This is by no means a definitive list of all the template tags available. For the full list, check out the Template Tags entry in the WordPress Codex.