
Many people asked me if it is possible to use WordPress shortcodes in theme files. Yes, it is – Follow this simple recipe to get started!

Many people asked me if it is possible to use WordPress shortcodes in theme files. Yes, it is – Follow this simple recipe to get started!
Assuming the want to use a shortcode named [my_shortcode], you'll have to do the following and use the do_shortcode() function:
<?php echo do_shortcode("[my_shortcode]"); ?>
Easy and super useful.
Thanks to WP Snippets for the tip!
6 Responses
Another alternative is to directly call the function which is executed by the shortcode, as the shortcode is essentially just a wrapper function
Thanks for the tips, sometimes we stuck in a problem that how we use shortcode in anywhere we use and we dont need to use wordpress editor,so it can surely remove that problem.
Yeah i’ve never really used shortcodes but alternatively directly calling the function, what befits are there in useing the shortcodes?
Cheers
This is a good way of making use of shortcodes in template files, but how could I add a snippet of PHP code directly into the content of a page or post?
Which is the best way, using shortcode or adding command line in functions.php?
Well calling a Function is more nice then shortcode, and also you can use function_exists to avoid any further problems, if the function is deleted then the Theme Might show some errors which is very bad on live websites, so you the function will not run, if it is deleted
Trackbacks: