The muplugins_loaded WordPress PHP action fires once all must-use and network-activated plugins have loaded.
Usage
add_action('muplugins_loaded', 'your_custom_function'); function your_custom_function() { // your custom code here }
Parameters
- None
More information
See WordPress Developer Resources: muplugins_loaded
Examples
Register a Custom Post Type
Register a custom post type after all must-use plugins are loaded.
add_action('muplugins_loaded', 'register_custom_post_type'); function register_custom_post_type() { // Register a custom post type called "book" register_post_type('book', array( 'public' => true, 'label' => 'Books' )); }
Load a Custom PHP File
Load a custom PHP file from the mu-plugins directory.
add_action('muplugins_loaded', 'load_custom_php_file'); function load_custom_php_file() { // Load a custom PHP file require_once(WPMU_PLUGIN_DIR . '/custom-file.php'); }
Enqueue a Custom Script
Enqueue a custom script file after all must-use plugins are loaded.
add_action('muplugins_loaded', 'enqueue_custom_script'); function enqueue_custom_script() { // Enqueue a custom script file wp_enqueue_script('custom-script', WPMU_PLUGIN_URL . '/custom-script.js', array('jquery'), '1.0.0', true); }
Initialize a Custom Class
Initialize a custom class after all must-use plugins are loaded.
add_action('muplugins_loaded', 'initialize_custom_class'); function initialize_custom_class() { // Initialize a custom class $custom_class = new Custom_Class(); }
Register Custom Taxonomy
Register a custom taxonomy for a custom post type after all must-use plugins are loaded.
add_action('muplugins_loaded', 'register_custom_taxonomy'); function register_custom_taxonomy() { // Register a custom taxonomy called "genre" for "book" post type register_taxonomy('genre', 'book', array( 'label' => 'Genres', 'rewrite' => array('slug' => 'genre'), 'hierarchical' => true, )); }