Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

1 Answer 1

up vote 7 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

 
discard

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.