Beginner's Guide for WordPress - Start your WordPress Blog in minutes.
Choosing the Best
WordPress Hosting
How to Easily
Install WordPress
Recommended
WordPress Plugins
View all Guides

How to use Shortcodes in your WordPress Themes

Last updated on by
Elegant Themes
How to use Shortcodes in your WordPress Themes

Recently, we got a request from a user asking how they could use WordPress shortcodes in their WordPress themes. Shortcode is a special tag that you can enter into a post that gets replaced with different content when actually viewing the post on the website. If you have ever embedded a WordPress gallery on your blog, then you’ve already seen the built in shortcode. Check out our article on adding shortcodes in your themes.

Thankfully, WordPress has a very easy function called do_shortcode() that lets you add shortcodes in your themes. Simply add the code like this:

<?php echo do_shortcode("[example_shortcode]"); ?>

Simple and easy :)


Editorial Staff at WPBeginner is a team of WordPress lovers led by Syed Balkhi. Page maintained by Syed Balkhi.

WPBeginner's Video Icon
Our HD-Quality tutorial videos for WordPress Beginners will teach you how to use WordPress to create and manage your own website in about an hour. Get started now »

Comments

  1. DavidA says:

    Hello, I have two wordpress blogs on multisite.
    Do you know, how to use the shortcode on the website 1 from the website 2 ?
    Thx

  2. Riaz Kahn says:

    Thanks, Its Working Well.

  3. Dean says:

    Sorry here is the code:

    CODE: ——————————————————————————————

    echo do_shortcode(“[tabset tab1="tab 1 title" tab2="tab 2 title"]
    [tab]tab 1 content[/tab]

    [tab]tab 2 content[/tab]
    [/tabset]“);

    —————————————————————————————————-

  4. Michael Atkins says:

    It may be more efficient to use the method outlined by Konstantin Kovshenin at http://kovshenin.com/2013/dont-do_shortcode/

  5. Nate Rouch says:

    That’s good information. I’ve been searching for a way to simply add these, I appreciate it.

  6. Tim says:

    Great info. Thanks! However, it’s not working for me in WordPress 3.5.1 using the Avada theme.

    Do you need to add anything to functions.php for the code above to work? Could this be a theme-specific issue? Thanks, just learning wordpress templating.

  7. Anthony says:

    thanks loads man! this saved me hours of internet searching :)

  8. Tyron says:

    This is a great little tip. How would this work if your content needs to be wrapped in a shortcode?

    Like [shortcode-name]Content here[/shortcode-name].

    • Jonathon Harris says:

      Tyron,
      This a late answer as I’m just seeing it, but to include wrapped content, you could do the following:

      echo do_shortcode(‘[example_shortcode]‘.$text_to_be_wrapped_in_shortcode.’[/example_shortcode]‘);

      Cheers,
      J

  9. pratik.chourdia says:

    Wow.. worked :) thanks

  10. Homepage Kasugai says:

    sfg

  11. Homepage Kasugai says:

    This is exactly what I was looking for. Helpful. Thank you.

  12. krushna says:

    yes..i am also interested to know ..where to write the code. if there will be example that wud be great.

    • Editorial Staff says:

      You add it anywhere you want to display the shortcode in your theme files. It can be in your sidebar, footer, or wherever you want.

  13. Keith Davis says:

    Hi boys
    Where do you add the code…

    What file do you add it to and where abouts in the file?

    My theme already uses shortcodes but it would still be interesting to know.

  14. Jim says:

    I came across the need for this just the other day – to add a shortcode outside of the loop. Thanks!

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.