What is a WordPress Action? An Action is a WordPress code-specific function that runs at specific points throughout the WordPress core. The WordPress core has many pre-defined Actions, also known as Action Hooks, that let developers insert custom code at these points. Action hooks are part of what makes WordPress extensible, allowing the development of plugins and custom themes. Most WordPress plugins and themes depend on Actions to operate.
How to Add Action Hooks in WordPress
To give you an example of how WordPress Actions are used to add code to your WordPress site, let us pretend you need to change the copyright information in your footer area because the theme you chose doesn’t have that option. You could modify the code directly in your theme or create a child theme. In some cases, depending on the project, this may be preferable. But most of the time, it’s considered better practice and much easier to hook your code to a pre-defined Action already being executed.
To add your custom copyright code, you’ll want to place it into a function called a Callback and add it to your WordPress theme’s
function.php file. Now add the function to an Action in the spot you would like your copyright code executed.
WordPress Action Example:
This example shows the
custom_copyright_notice action hooked into the
wp_footer Hook. The
custom_copyright_notice function will be executed every time the
wp_footer() Hook appears throughout your WordPress theme code.