This action hook is fired once WordPress, all plugins, and the theme are fully loaded and instantiated.
add_action( 'wp_loaded', 'your callback function' );
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 } });
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.
Since: 3.0
The wp_loaded action is located in wp-settings.php