If you have been using WordPress for some time, chances are you came across a Shortcode. In this blog post we’ll talk about what are shortcodes, how to use them and what you can achieve with them.
Shortcodes act as shortcuts to add information or embed data in your website easily. They were introduced back in WordPress 2.5 and are specific to WordPress.
Many plugins make use of shortcodes and you can even create your own, but, by default, WordPress supports these shortcodes:
To explore in detail what each of them does, read Shortcode « WordPress Codex
Pretty useful, right!
Shortcodes in CreativeMinds’ Plugins
Most of our plugins offer shortcodes in one way or another. For instance, with the Booking Calendar plugin you can add different calendars to any page with them.
The Questions and Answers plugin has shortcodes that display question tables.
One feature that makes shortcodes extra powerful is the parameters.
They help making the shortcode more specific and usually come in two types: filtering parameters and view parameters.
Filtering parameters specify what data the shortcode will display. For instance, only videos published by a certain channel.
View parameters specify how the generated content should look like. For instance, they can define if the embedded video player will have full screen option or not.
Do I Have To Memorize Them?
No, not at all! They were designed precisely to make the life of those who don’t code easier.
For that reason, you can always see the full list of shortcodes in two places:
- The documentation of the plugin (For example, CM Answers (CMA) – Shortcodes – Using Shortcodes)
- The plugin settings, in the Shortcodes submenu. Clicking the link will direct you to a page listing all the shortcodes and its parameters.
Ok, enough theory! Time for some practical knowledge.
For instance, if you are using the Questions and Answers plugin and try this:
You will return a list of all questions.
But what if you want to show only questions related to the category “sports”? You can apply the “cat” parameter, and the end result will be.
Note that sometimes you can list multiple values into a parameter, such as:
[cma-questions cat=”sports, art, cinema”]
This will result in a table with only questions inside the categories sports, art and cinema.
Finally, remember that you can (and should!) use multiple parameters. The shortcode below generates a table with questions from the categories sports, art and cinema and also limits the table to five questions at once.
[cma-questions cat=”sports, art, cinema” limit=5]
- Yes/No – Many parameters are about turning on and off a certain feature. When that is the case, usually you will use “0” to turn the feature off and “1” to turn them on.
will display the questions table with the post date of each thread, while
will hide the date.
- Hidden Parameters Still Count – Remember that some parameters have default values that will be applied even if you don’t write down that parameter inside the shortcode.