WordPress template tags are little custom functions that can be used by WordPress administrators in their themes and throughout their WordPress site to perform a bunch of tasks. Usually that's going to be getting and outputting something. More simply put: they're functions that can be used in WordPress templates. Sometimes they output authors or posts or categories or short links or something like that. For plugin developers, this is another way we can add functionality to WordPress, creating our own template tags. The Codex has some information about template tags, and it actually lists the template tags that are currently available inside of WordPress.
For example, here is one: bloginfo. You can use bloginfo to get different types of data inside of your WordPress blog. To use it, let's go ahead and log into our WordPress admin, and under Appearance, there is an option for Editor. This allows administrators to edit their themes directly, and you can see they can select which theme they want to edit-- In this case, Twenty Ten, which is the default theme that comes with WordPress 3.0--and we're going to choose Main Index Template. We'll scroll down to the bottom, and you can see they have some template tags in here that get the sidebar and get the footer, and we are going to add another one, bloginfo, and we are going to get description.
So, it's as simple as that. I update the file, which will save it, and I can go ahead and launch my blog site, and if I scroll down, you'll see at the bottom of the site, after the footer, I have my description. To create your own template tag, if you remember, every WordPress plugin file is included automatically in the request, which means not only is the code that isn't in function is included, the functions themselves are included. So, in this example, I have an add_copyright function. This will essentially become a template tag.
You can see it just outputs a little copyright message directly to the screen. So, if I want to use this, I can go back into my administrator, in the Edit Themes, I'll scroll down, and instead of outputting my blog description, I am going to use add_copyright. In order to make this work, I need to make sure that I first check on my plugin, My copyright plugin, and make sure that it's activated so that it's actually included in the file. Now that it's activated, I can go to the front-end of the web site and refresh, and you can see it's included my template tag with my copyright message.
WordPress allows us to build our own template tags. These are essentially functions that can be run via PHP from within any template in the WordPress environment. What's great about the plugin API is that any function in our plugin files will automatically be included in WordPress requests. So, everything you write can be used this way. The main thing is if you want to expose these functions to your administrative users, you need to make sure and provide some sort of documentation so they know what's there.
Get unlimited access to all courses for just $25/month.Become a member
82 Video lessons · 98434 Viewers
61 Video lessons · 85719 Viewers
71 Video lessons · 69638 Viewers
56 Video lessons · 101962 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Your file was successfully uploaded.