use wordpress shortcode in template

Posted: July 23, 2012 in Wordpress knowledge base

While making a custom wordpress theme from static html, sometime we need to show shortcode within our template file for a image gallery or for some other plugin.
Wordpress provide a custom builtin funcion that parse the shortcode to required result.

Syntax: <?php do_shortcode(‘[your shorcode goes here]’); ?>

Example:
<?php echo do_shortcode(‘[shortcode id=id]’); ?>

You can use the same code withn the widgets, but in order to parse php within widgets you have to install a plugin like “Exec-PHP” to parse php.Then use text widget and write the same syntax written above to get the desired result.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s