Use WordPress Shortcode in Template File

  • follow us in feedly
Published March 24, 2013 by Brad Knutson
WordPress Shortcode in Template

So you’ve spent all this time building these awesome custom WordPress shortcodes, but now you want to use them in a theme template file. What are you supposed to do? Sure…you could rewrite the function and use it in your template file, but why would anyone want to do that? Proper code etiquette says that rewriting code is a big no-no.

Thankfully, WordPress comes to the rescue again, with the do_shortcode() function. This function allows you to recall a shortcode that you built in your functions.php file and use it pretty much anywhere else you want.

Enter the code below in your header.php, footer.php or any other template file.

<?php echo do_shortcode("&#91;shortcode&#93;"); ?>

Change our the shortcode to whatever you named your shortcode, and that’s all there is to it.

This useful snippet has gotten me out of jams more than a few times.

The following two tabs change content below.
Founder at Inbounderish
Brad Knutson is a Web Developer in the Twin Cities area of Minnesota. He has experience working with WordPress and Drupal, and also has an interest in SEO and Inbound Marketing.

Keep Up-to-Date



See a complete list of topics discussed in blog posts here.

Check These Out

Get 2 Weeks Free! Sign Up Today! Premium Managed WordPress Hosting Genesis Framework for WordPress SEO is complex. Tools should be simple. Thesis Theme for WordPress:  Options Galore and a Helpful Support Community

Share Your Thoughts

Your email address will not be shown.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">