do_action( 'wp_loaded' )

This hook is fired once WP, all plugins, and the theme are fully loaded and instantiated.


Description

Ajax requests should use wp-admin/admin-ajax.php. admin-ajax.php can handle requests for users not logged in.


Top ↑

More Information

AJAX requests should use wp-admin/admin-ajax.php. admin-ajax.php can handle requests for users not logged in.

The wp_loaded action fires after init but before admin_init.

Front-End: init -> widgets_init -> wp_loaded
Admin: init -> widgets_init -> wp_loaded -> admin_menu -> admin_init


Top ↑

Source

File: wp-settings.php. View all references

do_action( 'wp_loaded' );

Top ↑

Changelog

Changelog
Version Description
3.0.0 Introduced.

Top ↑

User Contributed Notes

  1. Skip to note 1 content
    Contributed by Steven Lin

    Migrate from Codex:

    Minify HTML codes when page is output

    add_action( 'wp_loaded','my_minify_html' );
    function my_minify_html() {
    	// Use html_compress($html) function to minify html codes.
    	ob_start('html_compress');
    }
    
    function html_compress( $html ) {
    	// Some minify codes here...
    	return $html;
    }

    If you only want to load a function only in the front end.

    // If u want to load a function only in the front end.
    add_action( 'wp_loaded', 'my_front_end_function');
    function my_front_end_function() {
        if ( !is_admin() ) { 
            // Only target the front end
            // Do what you need to do
        }
    }

    Same as above, but using anonymous function (PHP 5.3 or higher).

    add_action( 'wp_loaded', function () {
        if ( !is_admin() ) {
            // Only target the front end
            // Do what you need to do
        }
    });

You must log in before being able to contribute a note or feedback.