How to add a WordPress shortcode outside of the post editor or PHP templates


Shortcodes were introduced back in WordPress 2.5. Shortcodes are for creating macros to be use in a posts. For instance, the following shortcode (in the post/page content) would add a photo gallery into the page:

[  gallery  ]

If you want to use that shortcode outside of the WordPress post or page editor or PHP templates , you can use this snippet to output from the shortcode’s handler(s):

// Use shortcode in a PHP file (outside the post editor).
echo do_shortcode('[  gallery  ]');

sources: WordPress codex


Comments

One response to “How to add a WordPress shortcode outside of the post editor or PHP templates”

Leave a Reply

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

%d bloggers like this: