Recently a reader asked how to add the time of a post to a theme, so I thought I would give a basic overview of WordPress template tags. This is one of those things that seems like it must be really complicated, but actually isn’t.
What is a template tag? Template tags are used within your blog’s code to display information dynamically. They pull information from your mySQL database that your blog runs on, and allow you to display it using a simple via a PHP tag. PHP is the coding language that makes your blog work, while CSS is the code that makes your blog look the way it does.
To display the time, first we need to find out what the template tag is from the list in the WordPress codex. You’ll see if you follow the link, all the various template tags available. In the Date & Time section, we see that the template tag for the time is “the_time”. Clicking on the link for that tag gives us more detail about the options available, and even gives us an example exactly like what we’re looking for.
Now, we need to know where to put it in our theme files. We’ll use the DIYTheme as an example, but the code for your theme should be pretty similar. If you go into the Presentation tab, and then choose Theme Editor, you’ll see the list of files available for editing on the right side. Click on the one called “Main Index Template” or “Index” or something of that nature, and you’ll see the code in the left side window. Before you make any changes, copy all the code in the window and paste it into a text document somewhere, just in case it gets goofed up. Then, find the section with the following code in it (not too far down in the DIY Theme):
and then just add in the template tag for the post time wherever you’d like. I added it after the date:
Click the Update File button, and it will save your changes. Visit your site and make sure the changes worked. Keep in mind that your theme may also have a Single Post file where the code looks very similar to the one we just edited, that you may want to add the same template tag to. And, that’s all – that was easy right?