O'Reilly logo

Professional WordPress® Plugin Development by Justin Tadlock, Brad Williams, Ozh Richard

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 10. The Shortcode API

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.

CREATING SHORTCODES

This section teaches you what a shortcode is and how to create new shortcodes, from simple string replacements to advanced functions with parameters.

What Shortcodes Are

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. 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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required