admin_init

Home » Hooks » admin_init

The admin_init hook in WordPress is a crucial hook that gets triggered when the admin area of WordPress is initialized. This hook is used primarily to load the essential scripts, styles, and functionality in the WordPress admin area.

The admin_init hook is one of the earliest hooks that get triggered in the WordPress admin area. It gets triggered after WordPress core has loaded and after all the required files and plugins have been included. This hook is used to perform various tasks such as registering custom post types, creating custom meta boxes, and more.

Here is an example usage code for the admin_init hook in WordPress:

function my_custom_function() {
   // Your code here
}
add_action( 'admin_init', 'my_custom_function' );

In the above example, we are creating a custom function named my_custom_function. We then use the add_action function to attach it to the admin_init hook. This means that the my_custom_function function will be executed every time the admin area of WordPress is initialized.

Overall, admin_init is a powerful hook in WordPress that allows developers to add custom functionality and scripts to the WordPress admin area.

Learn More on WordPress.org

Register an account to save your snippets or go Pro to get more features.