WHAT'S IN THIS CHAPTER?
Creating custom shortcode
Registering complex and parameterized shortcodes
Mastering advanced shortcode tips
Connecting your site with Google Maps
Shortcodes are WordPress-specific code that enables you to do nifty things with little effort, such as embed content or create objects that would normally require lots of complicated, ugly code.
In this chapter, you learn how to allow users of your plugins to enhance their posts with advanced customizable content using just a few characters.
This section teaches you what a shortcode is and how to create new shortcodes, from simple string replacements to advanced functions with parameters.
The Shortcode API enables creating simple macro codes, sometimes also referred to as bbcodes for their similarity with a popular syntax in various forums and bulletin boards.
In a nutshell, a shortcode is a simple tag syntax between square brackets, such as
[something], used in posts. At render time when the post is displayed, the shortcode is dynamically replaced with a more complex and user-defined content. See Figure 10-1 for a simple example of a shortcode plugin that would substitute
[date] with the current date and time.
Figure 10.1. FIGURE 10-1
WordPress out-of-the-box registers shortcodes you can use: When you upload multiple images attached to a given post, you can ...