Components of a WordPress Template Tag
A WordPress theme is a collection of WordPress templates made up of WordPress template tags. As the core component of WordPress templates and plugin functions, you need to understand what makes up a template tag, as well as the correct syntax, or function, for a template tag as it relates to PHP.
WordPress uses PHP commands to pull information from the MySQL database. Every tag begins with the function to start PHP and ends with a function to stop it. In the middle of those two commands lives the request to the database that tells WordPress to grab the data and display it.
A typical template tag, or function, looks like this:
<?php get_info(); ?>
This example tells WordPress to do three things:
<?php : Start PHP.
get_info(); : Use PHP to get information from the MySQL database and deliver it to your site.
?>: Stop PHP.
In this case, get_info()represents the tag function, which grabs information from the database to deliver it to your site. The information retrieved depends on what tag function appears between the two PHP commands.
Every PHP command you start requires a stop command. For every <?php, you must include the closing ?> command somewhere later in the code. PHP commands structured improperly cause really ugly errors. You will find a lot of starting and stopping of PHP throughout the WordPress templates and functions.
Always make sure the PHP start and stop commands are separated from the function with a single space. You must have a space after <?php and a space before ?> if not, the PHP function code doesn’t work.