Shortcode in a WordPress Template

Introduced in WordPress 2.5, shortcodes are small snippets that you insert into posts and pages that call in certain things. What if you wanted to insert a shortcode into a WordPress template though like index.php? If you write the shortcode directly into the template it won’t work.

So to get a shortcode to render through a WordPress template just insert the short PHP snippet below replacing the “insert shortcode here” with your shortcode.

<?php echo do_shortcode("[insert shortcode here]"); ?>

Leave a Reply