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.
WordPress snippets using the admin_init hook
-
How to Restrict User Access in WordPress: A Comprehensive Guide
-
How to Restrict Dashboard Access in WordPress: A Complete Guide
-
Create a plugin to scan local.ch, and extract site data including: email, website, metaname generator, wordpress version
-
How to Redirect Based on User Roles or Capabilities in WordPress
-
Enabling Contributors to Upload Files: A Step-By-Step Guide for WordPress