Shortcode Intro

Use this sections index page.

Introduction

A Shortcode is a WordPress-specific code that is used in post/page content or the section widget to execute a piece of dynamic code.

For example, the shortcode [year] will display the current year. The word “year” is the shortcodes identifier/name. How can this be useful? Well if you ever write, “In 2010 things will be different” and want 2010 to automatically correspond to the current year, you can just write “In [year] things will be differrent” and the year will automatically correspond to the current year.

In other words, a shortcode is a WordPress-specific code that lets you do nifty things with very little effort.

Example


Simple Shortcode

[shortcode]

Basic Shortcode

In most cases a shortcode will incases content or other shortcodes. If this is the case then the shortcode will need to have an open and a close.

[shortcode] Some Content [/shortcode]

The “/” indicates the closing and is very important to the shortcode process.

More Advanced Shortcode

Often shortcodes will have an attribute with a specific parameter that can give the user more options for the feature.

[shortcode attribute="parameter"] Some Content [/shortcode]

Note: A shortcode attribute is a preset variable with preset parameters. Meaning that the attribute is not a customizable name and should be in the user documentation.

Here is a working example where “column” is the shortcode identifier/name, “size” is the attribute”, and “2” is the parameter. The end result would be a column with the width of 2 columns.

[column size="2"] Some Content [/column]