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

How to use Shortcodes in your WordPress Themes

Last updated on by
Follow WPBeginner on YouTube
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 »
  • DavidA

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

    • WPBeginner Support

      You can create a Network Wide Plugin and then both blogs can use the shortcode.

  • Riaz Kahn

    Thanks, Its Working Well.

  • Dean

    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]


  • Michael Atkins

    It may be more efficient to use the method outlined by Konstantin Kovshenin at

  • Nate Rouch

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

  • Tim

    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.

  • Anthony

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

  • Tyron

    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

      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]’);


  • pratik.chourdia

    Wow.. worked :) thanks

  • Homepage Kasugai


  • Homepage Kasugai

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

  • krushna

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

    • Editorial Staff

      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.

  • Keith Davis

    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.

  • Jim

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