5

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
| improve this question | | | | |
8

You can execute shortcodes using the do_shortcode() function

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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