So you’ve spent all this time building these awesome custom WordPress shortcodes, but now you want to use them in a theme template file. What are you supposed to do? Sure…you could rewrite the function and use it in your template file, but why would anyone want to do that? Proper code etiquette says that rewriting code is a big no-no.
Thankfully, WordPress comes to the rescue again, with the
do_shortcode() function. This function allows you to recall a shortcode that you built in your
functions.php file and use it pretty much anywhere else you want.
Enter the code below in your
footer.php or any other template file.
<?php echo do_shortcode("[shortcode]"); ?>
Change our the shortcode to whatever you named your shortcode, and that’s all there is to it.
This useful snippet has gotten me out of jams more than a few times.