Creating a Template

By now, you've probably realized that template tags in WordPress are just plain old PHP functions. Some take arguments, some don't. Some echo their results by default; others return the results for use in other functions. Creating a new template tag for your plugin is as simple as deciding what sort of function you need to write and whether it should return a value or echo it to the screen. Listing 9-2 shows a very simple example, and Figure 9-1 shows the results.

Listing 9-2. A simple template tag function today() {

$format = get_option('date_format'); echo date($format);

Figure 9-1. The results of the today() tag when placed above the Loop
0 0

Post a comment