Just as you might imagine, a shortcode is a tiny snippet of code that can be used to perform a number of functions. Essentially, shortcode is a specific form of shortcut used to perform a certain function or display a block of code without having to write out the entire code each time. It is typically used in content management systems (CMS) such as WordPress to make adding complex content to posts or pages easier.
Shortcodes were first invented for WordPress version 2.5 and have been included in all newer versions of WordPress since.
Shortcode In Action
A shortcode is, at its heart, an easier way to activate a function. For example, the shortcode “[ video ]“ is much easier to type and remember than the lengthier PHP code sequence used to embed a video into a page or a post.
Shortcodes are placed inside square brackets [ ] and can be inserted directly into the post or page editor. Some of them have parameters that can be used to customize their behavior, while others simply perform a specific function as is.
Some people refer to shortcodes as “macros” because they are preset commands that, when activated, execute a prewritten series of commands.
WordPress comes with several shortcodes already built in, including:
[ video ]
You can also create your own short codes or load more via a plugin.
Here are a few examples of what shortcodes can do in WordPress:
- : This shortcode would display a gallery of images. The id parameter specifies which gallery to show, and the size parameter specifies the size of the images.
- : This short code would embed an audio player in the page that plays the specified audio file.
- [contact-form]: This could be used to display a contact form, assuming you have a plugin installed that provides this functionality.
If you want to use a shortcode inside of a post, first, make sure that you’ve activated Text (instead of Visual). Then, insert the shortcode. But if you want to display the text of a shortcode inside a post, you’ll need to wrap it in double brackets. For example “[video]” is what you’d need to type in the text editor in order to show the text in your post.
Shortcodes can also come with attributes. For example, you can write [ video src=”mycoolvideo.mp4″ ] in order to embed the video “mycoolvideo.mp4” into a post.
Why Use Shortcode?
Note: Shortcodes can also be used in widgets starting with WordPress version 4.9.
Latest posts by Jamie Spencer (see all)
- Simple Step By Step Dreamweaver Tutorial – 2023 - May 6, 2023
- Best GoDaddy Alternatives for Domain Names or Web Hosting - May 3, 2023
- 12 Free Mockup and Wireframing Tools for Web Designers - May 1, 2023