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 remove category & tag base from WordPress URL

    Would you like to remove the category & tag base from WordPress URL? Do you need custom URL's? It's a super simple!...

    How to Disable Right Click on WordPress

    Are you worried about having your images stolen from your WordPress website? Then you need to know how to disable right click on...

    How to redirect HTTP to HTTPs in .htaccess

    Today's standard is to have an https certificate. Google will love you if your sites are secured. So https is not standard,...

    How to fix TypeError: $ is not a function in WordPress

    We can guess. You purchased a theme or plugin and a console shown a message "TypeError: $ is not a function"? Ok,...

    How to fix Unknown collation: ‘utf8mb4_unicode_520_ci’

    Unknown collation is probably caused because your local and live server are running different versions of MySQL. This problem mostly comes when...

    Related Stories

    Leave A Reply

    Please enter your comment!
    Please enter your name here

    Stay on op - Get the daily news in your inbox