What is: Shortcode

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?

Shortcodes are primarily used for people wanting to perform simple commands inside of a post, page, or widget. They offer a way to add complex or dynamic content to a post or page without needing to know how to write out the code directly. They’re especially useful for functionality that you want to use repeatedly across your site. Instead of writing out the full HTML, CSS, or JavaScript each time, you can simply use a shortcode.

Note: Shortcodes can also be used in widgets starting with WordPress version 4.9.

The following two tabs change content below.

Jamie Spencer

My name is Jamie Spencer and I have spent the past 10 years building money making blogs. After growing tired of the 9-5, commuting and never seeing my family I decided that I wanted to make some changes and launched my first blog. Since then I have launched lots of successful niche blogs and after selling my survivalist blog I decided to teach other people how to do the same.