How To Call Shortcode Within a WordPress template


Most WordPress plugins and widgets offer their functionality through shortcodes. Now one of the questions many people are asking is on how to call a shortcode within a WordPress template or how to use shortcodes within a WordPress template.

So if you are one of those people who are wondering how to call shortcodes or use shortcodes within a WordPress template, I’ll have you sorted. I’m going to reveal the answer I’ve been sharing in many forums. But before then, let’s first understand what WordPress shortcodes are.

Shortcodes in WordPress

These are special tags that allow you to add a bunch of cool things to your site’s pages and posts. Some of the things you can add to your site using these shortcodes include galleries, column layouts, contact forms, buttons, social media buttons, blockquotes and much more.

Through WordPress shortcode API, you can easily create your own WordPress shortcodes and add them to pages and posts. But what if you want to use WordPress shortcodes within WordPress templates instead of within pages or posts? You can do this by adding various functions to the functions.php template. Read on to find out how you can do this.

Adding Shortcodes in the PHP template

There are several ways you can do this. The one I recommend most in various forums is through the standard WordPress do_shortcode function. This function was created specifically to accomplish this task. However, before you insert this function in the theme template, you need to add a little PHP coding prior to that.

Use this code:

<?php echo do_shortcode("[place your plugin shortcode here]"); ?>

Sometimes this shortcode may fail to work simply because of the double quotation marks in them. If this is the case, then try it out with single double quotation marks as shown below.

<?php echo do_shortcode('[place your plugin shortcode here]'); ?>
If your page is calling the shortcode template instead of its respective name, just try the code below.
<?php echo do_shortcode ('[place your plugin shortcode here]' ('name of your shortcode' ) ); ?>
For instance, if it’s the Contact Form shortcode you want to place into your theme’s template, try something like:
<?php echo do_shortcode('[CONTACT-FORM]'); ?>
If you still need help on how to call Shortcode or use shortcodes within a WordPress template or any other WordPress related questions, just feel free to let me know. I will be happy to help you.

Add comment

Recent Posts


Recent Comments