What is: Action

An action is a function in WordPress code that is run at certain points throughout the WordPress core. In WordPress code there are numerous pre-defined actions or hooks that allow developers to add their own code at these points. These are a part of what makes WordPress so extensible and most plugins depend on actions for their operation.

To give you an example of how they can be used to add code to a website let us assume that you want to add a copyright notice to your footer. In order to do this you could modify your footer template directly. In some cases this would be preferable but many times it is much easier, and better practice, to hook your code to a predefined action that is already being executed in the footer. To do this you can add your copyright code into a function in your functions.php file. You can then add this function to an action that is in the spot where you would like your copyright code to be executed.

function copyright_notice() {
   echo "Copyright All Rights Reserved";

In this example, copyright_notice is an action hooked into wp_footer hook. The function copyright_notice will be executed whenever the wp_footer() hook appears in a WordPress theme code.

WordPress offers a list of available actions in their Plugin API.

This post was originally published in the wpbeginner glossary.

Additional Reading