How To Display Shortcode In Templates

Shortcodes can easily be used in the post editor but sometimes there is requirement to use shortcodes in the template or theme files. Here is simple code snippet to display any shortcode outside the editor,

For the sake of more interest, let write a shortcode and display it in any template file,

1. Write a Shortcode – functions.php

We have written a simple shortcode in functions file to display WordPress version. Let use it in any template file,

2. Use Shortcode In Template Files

We can use any shortcode like above in our template files with the help of do_shortcode.


You may also be interested to learn about wrap images in div, wp_query pagination and use different single template per category.