WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Many plugins don't provide a documented way to access their functions from within PHP (e.g. when building a custom theme), but only shortcodes to insert in posts.

Is there a standard way of executing shortcode from within PHP as if it were part of the content? Like so (this is made up):

$gallery_html = execute_shortcode("{gallery}");  //  this would return the HTML  
                                                 //  that the gallery plugin returns
                                                 // in the context of the current post
share|improve this question
up vote 8 down vote accepted

You can execute shortcodes using the do_shortcode() function

$gallery_html = do_shortcode('[gallery]');
share|improve this answer
I somehow always misunderstood how this function works - it's that easy. Thanks! – Pekka 웃 Oct 6 '11 at 11:52

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.