wp_loadedaction-hookWP 3.0.0

Fires after WordPress is fully loaded, when the environment is completely ready to execute code for any request type.

Fires after init.

Fires once, when WordPress, all plugins, and the active theme are fully loaded. This is a late initialization point for code that waits until the environment is ready.

Unlike the init hook, in Multisite it does not fire if the current site is marked as deleted, archived, or spam. In that case, after init, the corresponding file, such as blog-deleted.php, is invoked and PHP execution terminates before this hook is called, so WordPress never finishes loading.

This event is declared in wp-settings.php.

Usage

add_action( 'wp_loaded', 'wp_kama_loaded_action' );

/**
 * Function for `wp_loaded` action-hook.
 * 
 * @return void
 */
function wp_kama_loaded_action(){
	// action...
}

Examples

#1 Early bootstrap after everything is loaded

Suitable for initializing services and connections that require the plugins and theme to have been loaded.

<?php
// Register the handler as early as possible on this event.
add_action( 'wp_loaded', 'my_project_bootstrap', 0 );

function my_project_bootstrap() {
	// Initialize the service locator, containers, and subscriptions to plugin and theme hooks.
	// All third-party code is now available and can be safely relied upon.
}

Changelog

Since 3.0.0 Introduced.

Where the hook is called

In file: /wp-settings.php
wp_loaded
wp-settings.php 801
do_action( 'wp_loaded' );

Where the hook is used in WordPress

wp-includes/class-wp-customize-manager.php 375
add_action( 'wp_loaded', array( $this, 'wp_loaded' ) );
wp-includes/class-wp-customize-widgets.php 113
add_action( 'wp_loaded', array( $this, 'override_sidebars_widgets_for_theme_switch' ) );
wp-includes/class-wp-rewrite.php 1520
add_action( 'wp_loaded', array( $this, 'flush_rules' ) );
wp-includes/class-wp-rewrite.php 1878
add_action( 'wp_loaded', array( $this, 'flush_rules' ) );
wp-includes/cron.php 1025
add_action( 'wp_loaded', '_wp_cron', 20 );
wp-includes/default-filters.php 567
add_action( 'wp_loaded', '_custom_header_background_just_in_time' );
wp-includes/default-filters.php 782
add_action( 'wp_loaded', '_add_template_loader_filters' );
wp-includes/deprecated.php 5885
add_action( 'wp_loaded', $fn_register_webfonts );