This whole appendix has been about useful references. We should take a quick look at shortcodes. They were first introduced in version 2.5. If you're comfortable with writing functions in WordPress, shortcodes can help you take longer bits of code (such as custom loops and complex template tag strings) or even just markup and text that you feel you'd use a lot in your theme (or plugin) and allow you to compress them in to cleaner, simpler bit of reusable code. You can add shortcodes to your theme's functions.php file.
You're probably familiar with shortcodes and may not realize it. If you've ever taken a look at how WordPress's media manager inserts captions into images, you've probably noticed something like:
[caption id="attachment_12" align="alignleft" width="150" caption="this is my caption"]<img src.../>[/caption]
That's a built in shortcode for captions and alignment in WordPress.
To create a shortcode, you do need to create a PHP function in your theme's functions. php file. If your theme does not have a functions. php file, simply create a new file and name it functions. php and place it in the root of your theme's directory.
Was this article helpful?