Understanding WordPress Shortcodes

Shortcodes are a common way for WordPress developers to extend functionality for website managers. Those new to WordPress and web publishing can find them a little intimidating, but they’re quite simple.

How Shortcodes Work

Shortcodes are like keywords that tell WordPress to “replace me with code.” This allows the content writer to execute blocks of code inline with the content.

The syntax for a shortcode is straightforward. In its plainest form, it’s a left square bracket, followed by the shortcode name, and then a right square bracket: [shortcode]. For WordPress themes I build, I often provide a contact form by shortcode. It’s implemented with something like this: [contact].

Only the shortcode is stored with the content. The code associated with a shortcode is executed before the server sends the webpage to the user. On the WordPress admin end, you see a shortcode, on the website, you see the executed code. For the [contact] example, the shortcode would be replaced with a functioning contact form.

Shortcode Button
The buttons on this website are made with shortcodes.
Shortcodes can also contain content and manipulate the content in some way. A button might be created in this way: [button link="http://www.google.com"]Visit Google[/button]. That could create a button with the label “Visit Google,” that, when clicked, took you to Google’s homepage. The first bracketed part is an opening tag for the shortcode, the second bracketed part, which begin’s with a slash, is a closing tag for the shortcode. The link="http://www.google.com" part is an attribute/value pair. Shortcodes are able to accept extra information that may modify the output. In this case, it provides the URL for the button.

To recap, here are the forms of shortcodes:

  • [shortcode]
  • [shortcode attr=“value”]
  • [shortcode]content[/shortcode]
  • [shortcode attr=“value”]content[/shortcode]

If a shortcode doesn’t exist, you’ll know because nothing will be different on your website. A wrongly used shortcode shouldn’t break your site, and if it does, you can fix it or remove it from your content. So there’s no reason to be afraid to try it.

Where Do I Get Shortcodes?

Shortcodes are added functionality; they don’t come as part of a clean WordPress install. They can be added by the theme in use or by plugins. Check the documentation for your theme or your plugins to see if there are associated shortcodes you can use. If I built your theme, then I went over any available shortcodes during our training session.

If you don’t have shortcodes at your disposal, that’s fine. You don’t need them. But if you are curious about how they might be able to help your content creation and workflow, contact me. We can talk about your needs and if some custom shortcodes are the best way to meet them.