Shortcodes
Shortcodes are a handy way to let a nontechnical person, that is, the editor of the website, include dynamic functionality within pages and posts, without having to actually use any PHP, complex HTML structures, or custom JavaScript. In other words, shortcodes are handy reusable pieces of code, yet they don't require any actual coding experience or knowledge on the end user's part.
Shortcodes and the way they work
The way a shortcode works is that you tell WordPress to look at text within square brackets ([]
) and evaluate it by running a PHP function. That PHP function can live in your functions.php
file of your theme, or in a plugin file, or in a widget file. Let's create a simple shortcode and include it in with our most recent widget, the one we were developing just a minute ago for showing a custom tag cloud.
Types of shortcodes
Shortcodes are a pretty simple concept by definition, but we can still distinguish three main types:
Single-tag shortcodes: These shortcodes are executed...