WinningWP content is free to all. If you make a purchase through referral links on our site, we earn a commission (learn more).

How to use WordPress shortcodes in page/theme templates

WordPress Deals

Plugins and widgets enable users to take advantage of a huge array of extra or additional functionality – from displaying a simple list of popular posts to conducting user polls or inserting complex forms. But what if you’d like to use some of that extra functionality somewhere other than in a page, post or sidebar widget? Like, say, in a WordPress page/theme template file?

Well, in much the same way that shortcodes (something we’ve already covered in relative depth in an earlier post) can often be used to take advantage of a plugin or widget’s functionality from within the WordPress visual editor (assuming the author of the plugin or widget in question created a shortcode for use with their plugin/widget in the first place), they can ALSO be used to insert the same functionality into a WordPress page/theme template…

Here’s how:

To use a shortcode in a page/theme template, simply wrap the standard WordPress do_shortcode function (created for this very purpose) with a little PHP coding – as follows (to be inserted wherever in the page/theme template file you’d like to enable your shortcode’s specific functionality):

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

…remembering of course, to substitute [insert-your-shortcode-here] for the shortcode you actually want to use.

Simple!

By Brin Wilson

Founder of WinningWP - passionate about all things WordPress! Find me on Twitter.
Comments (policy)
  1. Brian Victor Streeter says:

    Most likely your template spans across multiple php files and you customize. This function is not required. Merely, just type the shortcode in the html. The function will actually NOT work in customized plugins

Leave a Reply

Your email address will not be published. Required fields are marked *

All comments are held for moderation. We'll only publish comments that are on topic and adhere to our Commenting Policy.