[WP 101] What Are WordPress Shortcodes And How To Master Them


[WP 101] What Are WordPress Shortcodes And How To Master Them

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.

Related Stories:

Many plugins make use of shortcodes and you can even create your own, but, by default, WordPress supports these shortcodes:

[audio]

[caption]

[embed]

[gallery]

[playlist]

[video]

To explore in detail what each of them does, read Shortcode « WordPress Codex

Pretty useful, right!

business-2082639_1280 (1) blog cogs shortcodes

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.

Parameters

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.
    Shortcode menu plugin back-end

    Shortcode menu in the plugin back-end

Examples

Ok, enough theory! Time for some practical knowledge.

Example 1

For instance, if you are using the Questions and Answers plugin and try this:

[cma-questions]

You will return a list of all questions.

Dashboard showing questions posted by a user in the CM Answers plugin

Dashboard showing questions posted by a user in the CM Answers plugin

Example 3

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.

[cma-questions cat=”sports”]

Simple, right?

Example 3

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.

Example 5

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]

Extra Tips

  • 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.
    For example:
    [cma-questions dateposted=1]

    will display the questions table with the post date of each thread, while

    [cma-questions formontop=0]

    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.

Extra Resources