WordPress Shortcodes
What Are Shortcodes?
Shortcodes simplify the addition of features and functions within your WordPress site.
To quote WordPress "Think of a shortcode as a shortcut to add features to your website that would normally require lots of complicated computer code and technical ability."
WordPress comes with a set of built-in shortcodes, and many themes and plugins when activated also add their own shortcodes.
WordPress supports and expands shortcodes within the content of a Post, Page, or custom post type and within widgets.
Format of Shortcodes
WordPress shortcodes consist of a phrase enclosed in a set of square brackets [ ].
As an example, the WordPress shortcode for a gallery looks like this:
[gallery]
Shortcodes using attributes (parameters)
Shortcodes can also be used with additional attributes or parameters.
Shortcode attributes allow information to be passed to the shortcode processor. This information is required for many shortcodes to operate as desired.
Shortcode attributes are often referred to as parameters. This is the nomenclature that ActiveMember360 uses i.e. shortcode parameters.
The order of parameters is not relevant to the operation of shortcodes.
An example of a WordPress shortcode with parameters is:
[gallery id="123" size="medium"]
You can use single quotes, or double quotes to delimit the parameter values. If the parameter value contains no spaces the quotes are not strictly needed. When using quotes ensure they are ‘straight’ not ‘curly’ quotes.
So, all the following would be valid syntax:
[gallery id=123 size=medium]
[gallery id='123' size='medium']
[gallery id="123" size="medium"]
[gallery id='123' size="medium"]
[gallery id="123" size='medium']
However, for the following the only valid options would be:
[gallery columns='5' orderby='title DESC, ID ASC']
[gallery columns="5" orderby="title DESC, ID ASC"]
[gallery columns='5' orderby="title DESC, ID ASC"]
[gallery columns="5" orderby='title DESC, ID ASC']
[gallery columns=5 orderby='title DESC, ID ASC']
[gallery columns=5 orderby="title DESC, ID ASC"]
Shortcodes using start and end tags
Another form of shortcode can use start and end tags. The WordPress shortcode named caption uses this definition:
[caption]<img src="http://www.mysite.com/image.png">My image caption[/caption]