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.

How do shortcodes 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 theme by adding it to functions.php.

Creating a simple shortcode

Let's say you want to add a page with your bio on it and the text of your most recent post. Your bio won't change every day, but your most recent post will. We ...

Get WordPress 3 Complete now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.