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.

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.

Support Center Login

Our Login page has moved, Click the button below to be taken to the login page.

Social Media Login

   
Social Login Joomla

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

Post a Comment

Name:
Email Address:
Phone Number:
Comment:
Submit

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?

Search

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: support@InMotionHosting.com
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!