Components of a WordPress Template Tag
WordPress is based in PHP (a scripting language for creating web pages) and uses PHP commands to pull information from the MySQL database. Every tag begins with a 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 on your site, and they’ve been known to send programmers, developers, and hosting providers into loud screaming fits.
You find a lot of starting and stopping of PHP throughout the WordPress templates and functions. The process seems as though it’d be resource-intensive, if not exhaustive — but it really isn’t.
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. So make sure the code looks like this: <?php get_info(); ?> — not like this: <?phpget_info();?>.