:::: MENU ::::

WordPress – adding a shortcode into a template

In WordPress shortcodes are small snippets of code that run more complex functions and logic code. Shortcodes are great as they give the average editor the ability to serve up dynamic code on their site without having to understand any programming.

Shortcodes are designed to be placed in pages and posts, however every now and again you may wish to add a shortcode in a template file directly.   To do this you have to add a little bit more code. Lets take the wordpress maps plugin as an example.

The normal shortcode might look something like this:

 [wpgmza id='1']

To add this direct into the template change it to:

<?php echo do_shortcode("[wpgmza id='1']");

There you go – that’s all there is to it!


So, what do you think ?