If you’ve heard the term Shortcode while browsing around the WordPress world, or if you’ve seen the term used within instructions for a WordPress plugin and have been wondering what exactly a shortcode is and what it does, then you’ve found the right tutorial. Shortcodes are an awesome tool for both WordPress developers and WordPress administrators.
What is a Shortcode?
The definition from the WordPress Codex…
Introduced in WordPress 2.5 is the Shortcode API, a simple set of functions for creating macro codes for use in post content.
Huh? Let me put it a bit more simply. A Shortcode is a short code that you can insert into a post or page (and even a Widget) that will display some kind of content. Think of it like an abbreviation for a larger amount of code. All Shortcodes go between brackets, like this:
[shortcode]
Let’s imagine that we have a plugin installed that lets you create different lists of links grouped by topics. Let’s further imagine that you create a topic named Featured WordPress Tutorials and that you have added five links attached to that topic. Let’s also theorize that you wanted to put that list of links into several (but not all) of your WordPress pages or posts. How would you do that without manually creating those links again for each page or post where you wanted them to appear? If this plugin provides you with a Shortcode, it’s simple.
Where Do Shortcodes Come From?
As referenced above, WordPress introduced Shortcodes with the release of WordPress 2.5. This gave theme and plugin developers the ability to create Shortcodes for a multitude of uses…and us daily WordPress users a lot more options. I won’t get into how to create your own Shortcode just yet, so for now, let’s assume that the developer of our example Topics Link List plugin above built in some Shortcodes into his/her plugin for us to use. Let’s assume they provide the Shortcode below…
[topic list]
How and Where Do I Use a Shortcode?
Shortcodes can be used almost anywhere in WordPress. They could be built into your theme code, you could place them in your theme’s functions.php, comments pages, in your archive pages, etc. However, the most common use of Shortcodes are the ones provided by plugins that you place into your pages or posts when you’re creating or editing them.
Back to our example. So I’ve created my topic and some links within our hypothetical plugin settings and now I want them to show in this post. I would simply add the Shortcode below…
[topic list]
…and this abbreviation or short code would actually output my list like below:
Featured WordPress Tutorials
- Introducing the WP Modder App for iPhone and iPod Touch
- What is the best WordPress Plugin for Making a Personal Connection with Your Visitors?
- Speeding up Your WordPress Site by Limiting the Number of Post and Page Revisions
- How to Avoid Confusing Your New WordPress Authors and Only Give Them What They Need.
- How to Customize and Remove Items in Your WordPress Dashboard and Post Edit Screens
This is just a quick example and explanation of what Shortcodes are and how they might be used. I hope it gives you a starting point in understanding the real power and benefit of using Shortcodes in WordPress.
Can I Use a Shortcode in a Widget?
You sure can, but you’ll need to activate this feature in your theme first. See my other tutorial here or right on your iPhone, iPod Touch, or iPad by downloading the WP Modder App here.
Stay tuned here and at WP Modder to learn why and how to create your own Shortcodes.