Creating A WordPress Plugin Part 4: Template Tags

Screen shot 2012-05-01 at 11.44.52 PM

Please Check Out The Other Parts Of This Tutorial : Part 1, 2, 3, 4, 5

Okay so now we want to ad the feature of being able to create a template tag, just so that if they want to place a banner some where that isn’t in a post, or a widget area. We like to do things right, so the option is there if they want it.

Because of the simplicity of the plugin features, we are fortunate enough to have another simple task ahead of us.

We need to create the function that we will call inside of our template files. I’m choosing boss_banner() to make it short and easy to remember.

We will be grabbing the same 4 attributes we have been grabbing in the shortcode and widget: Link, Image, Width, and Height and then returning the results with the proper HTML

/* template tag <?php boss_banner('http://cssboss.com/wp-content/uploads/2012/02/cssbosslogo.png','http://www.cssboss.com'); ?> */
function boss_banner($image,$link,$width,$height) {
	return '<a href="'.$link.'"><img src="'.$image.'" alt="" width="'.$width.'" height="'.$height.'" /></a>';

Now anywhere in the template files, we can ad our template tag

<?php boss_banner('http://cssboss.com/wp-content/uploads/2012/02/cssbosslogo.png','http://www.cssboss.com'); ?>

and have our banner display correctly.

We will revisit this file when we come out with more features and update to newer versions in the future.

Please Check Out The Other Parts Of This Tutorial : Part 1, 2, 3, 4, 5