InMotion Hosting Support Center

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.


<?php has_action( $tag, $function_to_check ) ?>


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:


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.


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.

Was this article helpful?

Related Questions

Here are a few questions related to this article that our customers have asked:
Ooops! It looks like there are no questions about this page.
Would you like to ask a question about this page? If so, click the button below!
Ask a Question

Support Center Login

Our Login page has moved. Please click the button below to be redirected to the login page.

Post a Comment

Email Address:
Phone Number:

Please note: Your name and comment will be displayed, but we will not show your email address.

0 Questions & Comments

Post a comment

Back to first comment | top

Need more Help?


Ask the Community!

Get help with your questions from our community of like-minded hosting users and InMotion Hosting Staff.

Current Customers

Chat: Click to Chat Now E-mail:
Call: 888-321-HOST (4678) Ticket: Submit a Support Ticket

Not a Customer?

Get web hosting from a company that is here to help. Sign up today!