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.

Recent Articles

How to Hide Shipping Methods in WooCommerce?

This is a small detail, but WooCommerce doesn't have built-in any function for hiding shipping methods based on different situations. Imagine when...

How to Get WordPress Post Featured Image URL

Are you a WordPress developer or an advanced WordPress user? Whoever you are, sometimes you may need the direct URL of a...

How to Bulk Delete Media in WordPress

WordPress and media. That's the topic for a book. Sometimes is not easy to find what you need and when you have...

Custom Order Number for WooCommerce Will Saves You a Lot of Hassle!

WordPress is still the king of Content Management Systems (CMS). Thanks to its open-source nature, millions upon millions of users and PHP...

How to Manually Sort WooCommerce Products

WooCommerce is an e-commerce plugin for WordPress. It is a great way for the user to create an online store for their...

Get in touch

Be our first-class reader, build a community and follow us on social media!

Leave A Reply

Please enter your comment!
Please enter your name here