The has_action() WordPress function Updated on May 27, 2021 by Jeff Matson 1 Minutes, 5 Seconds to Read When writing a WordPress plugin or theme, you may need to check if an action hook exists before running additional code. In this article, we will show you the has_action WordPress function as well as how to use it. Usage <?php has_action( $tag, $function_to_check ) ?> Parameters The has_action function includes 2 parameters, on of them being required and the other optional. The following are the parameters that can be defined: $tag This parameter is simply the name of the action hook that you want to check for actions on. This is a required parameter as without it, the has_action function would not know what hook to check for. $function_to_check The $function_to_check is an optional parameter that can be used to check if a custom function has been hooked into the action. By default, it is set to false but if the custom function is defined here, it will return the priority of the function. If the function does not exist, it will return false. Code Example Determine if an action exists if ( has_action(‘my_hook’, ‘hooked_action’) ) { // do something } In the above example, we are simply checking to see if the hook my_hook has an action registered for it. If it does, additional code will be executed. Share this Article Related Articles How to Create and Edit Pages and Posts in WordPress What is the Difference Between Pages and Posts in WordPress How to Add Videos to WordPress How to Create and Add a Logo To WordPress How to Use a Custom Paypal Button in Your Website How to Track WordPress Vulnerabilities With WPScan How to Redirect WordPress Posts After Changing Permalinks W3 Total Cache – Guide to WordPress Caching How to Globally Change the Font in WordPress Create a Footer for WordPress