wp
Fires immediately after the global WP object is set: the global $wp variable has been defined. The hook fires at the end of wp().
The $wp object is passed to the callback by reference (&$WP).
This event is the first point at which query parameters have been parsed and the main query has already been executed and checked. See WP::main().
-
Use do_parse_request when you want to handle the current request yourself.
- Use parse_request when something must be done after the main request has been parsed but before it is processed (before the query itself is made). This is the most efficient point for changing, checking, or filtering the main WordPress request immediately after it is set but before WordPress performs any operations related to it.
Usage
add_action( 'wp', 'wp_kama_wp_action' );
/**
* Function for `wp` action-hook.
*
* @param WP $wp Current WordPress environment instance (passed by reference).
*
* @return void
*/
function wp_kama_wp_action( $wp ){
// action...
}
- $wp(object)
- The initialized WP object. Passed by reference.
Examples
#1 Usage example
Suppose all attachments must be redirected to the permanent /attach page.
Use the wp event because it is the earliest event at which conditional tags work:
add_action( 'wp', 'attachment_redirect' );
function attachment_redirect( $wp ){
if( is_attachment() ) {
$location = get_home_url() . '/attach';
wp_redirect( $location );
exit;
}
}
Changelog
| Since 2.1.0 | Introduced. |
Where the hook is called
wp
wp-includes/class-wp.php 838
do_action_ref_array( 'wp', array( &$this ) );
Where the hook is used in WordPress
wp-includes/class-wp-customize-widgets.php 357
add_action( 'wp', array( $this, 'customize_register' ) );