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
Special WordPress Hosting offer for WPBeginner Readers
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 experts 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 »


  1. Sonik says:


    I have written a shortcode of a gallery plugin in wordpress visual editor, but it is not executing the shortcode, instead it displays the shortcode as it is written.

    like if I write [test attr=’hello’], it echoes the same on webpage, not executing.


  2. Michael says:

    This is a fantastic post, thank you, I am just exploring shortcuts now for a website I am doing

  3. Art says:

    It doesn’t work in customizr theme. Anyone facing this issue?

  4. 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 ?

  5. Riaz Kahn says:

    Thanks, Its Working Well.

  6. 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]


  7. Michael Atkins says:

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

  8. Nate Rouch says:

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

  9. 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.

  10. Anthony says:

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

  11. 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:

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


  12. pratik.chourdia says:

    Wow.. worked :) thanks

  13. Homepage Kasugai says:


  14. Homepage Kasugai says:

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

  15. krushna says:

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

  16. 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.

  17. 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.