If you have a WordPress website, you've probably used, heard about or even unknowingly used shortcodes. You may have noticed the shortcode widget in Gutenberg or offered by various plugins. But what the heck are shortcodes — exactly?
Shortcodes are basically little snippets of text in box brackets that tell WordPress to do certain things when that shortcode is present within a page or post. You add a specified shortcode and WordPress runs the background code.
Before shortcodes you would have to actually write PHP code to create the layout or functionality you wanted. Now, with the help of talented developers, themes and plugins do all that for you. You just insert the provided shortcode and the magic happens.
If you have a WordPress website you have probably used the gallery shortcode at one time or another. It looks something like this: [gallery] .
This is the basic shortcode that WordPress inserts into a post when you use the Gallery block to a display gallery of photos that you just uploaded into WordPress on a page or post. You can add attributes such as size, columns, id, type, include, exclude and others to further customize how the gallery displays
A Little Shortcode History
Introduced on March 29, 2008 in WordPress 2.5, the Shortcode API, is a simple set of functions for creating macro codes for use in post content. It enables plugin and theme developers to create special kinds of content (e.g. forms, content generators) that users can attach to certain pages by adding the corresponding shortcode into the page text.
An example of a shortcode I use is with the contact form plugin I use on this site, Ninja Forms. Once I set up my Project Inquiry form to my liking in the plugin's control panel, I simply inserted the provided shortcode into a shortcode block on my Project Inquiry page and wallah! The form displays just the way I set it up.
I know I am dating myself, but back in the day before WordPress even existed, my Project Inquiry form would have required minimally HTML coding and a server side CGI script that had to be configured as well! Now with just a couple brackets and characters, anyone can add formatting to their site that would have been otherwise unavailable to non-developers.
Now can you see how shortcodes can make your life easier, right? Rare are the theme or plugin developers that are not are using the WordPress Shortcode API to offer shortcodes that make formatting or using their products much easier.
Can you create your own shortcodes on the fly?
The majority of shortcodes are provided by specific themes and plugins. The Gutenberg Editor that was added with WordPress 5.0 includes blocks that handle shortcodes much more. When converting content to Gutenberg, with the “Covert to Blocks” option, existing shortcodes will be converted into a shortcode block.
However, WordPress' built-in default set of shortcodes for those of you still using the Classic Editor plugin are there for your use. These shortcodes also have attributes that you can add to the shortcode to further customize to your needs:
The Gutenberg Editor that was added with WordPress 5.0 includes blocks that handle the above and much more.
Shortcode use and integration vary by theme, by developer and by plugin. When investigating new themes, within the theme demo you may find a menu tab “Shortcodes” to see what customized shortcodes will be available for your use.
An example of theme that creates a website dependent on shortcodes is Divi by Elegant Themes. ET uses shortcodes extensively in their Divi All-In-One WordPress Theme & Visual Page Builder. While this approach makes designing your website uber easy for non-developers, if you choose to no longer use Divi — you'll have to remove all those shortcodes which can be a complicated process.
Example Functionality of Shortcodes
Other examples of how shortcodes are used and integrated via themes and plugins:
- Author Info
- Column Layouts
- Content Boxes
- Custom Icon Lists
- Corporate Pricing Tables
- Toggled Content
- Tabbed Content
- Image Slider
- Easy Tooltips
- Social Media
- Password Protect Your Content
There is a varied selection of Shortcode related plugins for you to choose from and use on your site in the WordPress plugin repository. With the help of shortcodes you can now customize your site even further — without having to know any actual code. Magic.
At your service,
P.S. Disclosure: Some of the links in this post are “affiliate links.” Read my full Affiliate Disclosure Statement here.