O'Reilly logo

WordPress® All-in-One For Dummies® by Michael Torbert, Andrea Rennick, Kevin Palmer, Cory Miller, Lisa Sabin-Wilson

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

Identifying Functions within a Plugin

In a previous section, we explore how plugins interact with WordPress by using the plugin API. Here, we show you how functions are defined in a plugin. In PHP, a function is a predefined set of commands carried out when the function is called. It's the same in WordPress; some functions are common PHP functions, and some functions are specific to WordPress. We discuss how to hook into these functions through the plugin API so that you can call existing commands instead of having to write them over again in your plugin. However, you can also write your own functions and call them in your plugin.

So how do you identify functions within a plugin? Here's an example from the Hello Dolly plugin; this code function is found at the bottom, as the last line of the plugin file: hello.php:

add_action('admin_head', 'dolly_css');

The WordPress Codex documentation describes the add_action function as having the following arguments, or parameters:

add_action( $tag, $function_to_add, $priority, $accepted_args );
  • $tag is the name of the action you want to hook onto.
  • $function_to_add is the name of the function you're calling.
  • $priority is an optional value that represents how important the function is. The default is 10, a lower number makes the function run earlier, and a higher number makes the function run later.
  • $accepted_args is the number of arguments your function takes. This is optional, and the default is 1.

In PHP code, the dollar sign, $

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