What is Action in WordPress?

Action

Action is a function in WordPress code which keeps on running at certain point throughout the WordPress core. WordPress usually offers a list of available actions in their Plugin API. In WordPress code there are pre-defined actions. It enables designers to include their own code at these focuses. For example how it can be utilized to add code to a site let us expect that you need to add a copyright notice to your footer.

For doing this you could modify your footer template directly. In some cases this would be desirable but many times it is much easier to hook your code to a predefined action that is already being executed in the footer. For doing this you can add your copyright code into a function in your functions.php file. You would then be able to add this function to an action that is in the spot where you might want your copyright code to be executed.

function copyright_notice() {

echo “Copyright All Rights Reserved”;

}

add_action(‘wp_footer’,’copyright_notice’);

In the above example copyright_notice is an action hooked into wp_footer hook. The function copyright_notice will be executed at whatever point the wp_footer() hook shows up in a WordPress theme code.