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

1
1

You can execute shortcodes using the do_shortcode() function

$gallery_html = do_shortcode('');

Leave a Reply

Your email address will not be published. Required fields are marked *