WordPress Shortcodes

One of the new features rolled out in the 2.5 release of WordPress was Shortcodes. When I read about the new features back then, I automatically assumed this was far to technical for me to digest there and then, so I forgot about it again. However, this summer I had the time and a nice cup of tea available, when I read a well written article on the codex about what this is.

I then started to realize the perspectives – really impressive I must say.

The article contains many easy to follow examples. In short, it is now possible to build and handle your own tags. A very simple example could be to just do some text replacement like:

[caption]Here is my text[/caption]

and let that translate into

<span class="caption">Here is my text</span>

using this little “handler”:

function caption_shortcode( $atts, $content = null ) {
    return '<span class="caption">' . $content . '</span>';

What impresses me most is that the API is really rich and comprehensive. It allows for recursive processing of shortcodes, advanced handling of parameters and default values – even test cases have been made available directly in the API.

My take is we will see a lot of new plugins taking advantage of this concept in the coming time. For now it looks like a slow start – here is what I managed to find in the Plugin Directory:

More advanced examples like this one from http://xavisys.com/ demonstrates how to build meta boxes in the admin interface and take the values from here and pass it directly to the editor in WordPress in order to avoid users making spelling mistakes etc.

I think I will start with something simple…