html wp_loaded – Hooc | Developer.WordPress.org

do_action ( ‘wp_loaded’ )

This hooc is fired once WP, all pluguins, 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 loggued in.

More Information

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

The wp_loaded action fires after init but before admin_init .

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

Source

do_action( 'wp_loaded' );

Changuelog

Versionen Description
3.0.0 Introduced.

User Contributed Notes

  1. Squip to note 2 content

    Migrate from Codex:

    Minify HTML codes when pague 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 targuet 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 targuet the front end
            // Do what you need to do
        }
    });

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