Title: wp
Published: April 25, 2014
Last modified: February 24, 2026

---

# do_action_ref_array( ‘wp’, WP $wp )

## In this article

 * [Parameters](https://developer.wordpress.org/reference/hooks/wp/?output_format=md#parameters)
 * [More Information](https://developer.wordpress.org/reference/hooks/wp/?output_format=md#more-information)
 * [Source](https://developer.wordpress.org/reference/hooks/wp/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/hooks/wp/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/hooks/wp/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/hooks/wp/?output_format=md#user-contributed-notes)

[ Back to top](https://developer.wordpress.org/reference/hooks/wp/?output_format=md#wp--skip-link--target)

Fires once the WordPress environment has been set up.

## 󠀁[Parameters](https://developer.wordpress.org/reference/hooks/wp/?output_format=md#parameters)󠁿

 `$wp`WP

Current WordPress environment instance (passed by reference).

## 󠀁[More Information](https://developer.wordpress.org/reference/hooks/wp/?output_format=md#more-information)󠁿

The $wp object is passed to the hooked function as a reference (no return is necessary).

This hook is one effective place to perform any high-level filtering or validation,
following queries, but before WordPress does any routing, processing, or handling.
It is run in the [main()](https://developer.wordpress.org/reference/classes/wp/main/)
WP method in which the $query_args are passed to [parse_request()](https://developer.wordpress.org/reference/classes/wp/parse_request/),
as well as when [send_headers()](https://developer.wordpress.org/reference/classes/wp/send_headers/),
[query_posts()](https://developer.wordpress.org/reference/classes/wp/query_posts/),
[handle_404()](https://developer.wordpress.org/reference/classes/wp/handle_404/),
and [register_globals()](https://developer.wordpress.org/reference/classes/wp/register_globals/)
are setup.

## 󠀁[Source](https://developer.wordpress.org/reference/hooks/wp/?output_format=md#source)󠁿

    ```php
    do_action_ref_array( 'wp', array( &$this ) );
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/class-wp.php#L838)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/class-wp.php#L838-L838)

## 󠀁[Related](https://developer.wordpress.org/reference/hooks/wp/?output_format=md#related)󠁿

| Used by | Description | 
| [WP::main()](https://developer.wordpress.org/reference/classes/wp/main/)`wp-includes/class-wp.php` |

Sets up all of the variables required by the WordPress environment.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/hooks/wp/?output_format=md#changelog)󠁿

| Version | Description | 
| [2.1.0](https://developer.wordpress.org/reference/since/2.1.0/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/hooks/wp/?output_format=md#user-contributed-notes)󠁿

 1.   [Skip to note 3 content](https://developer.wordpress.org/reference/hooks/wp/?output_format=md#comment-content-4082)
 2.    [Collins Mbaka](https://profiles.wordpress.org/collinsmbaka/)  [  6 years ago  ](https://developer.wordpress.org/reference/hooks/wp/#comment-4082)
 3.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fwp%2F%23comment-4082)
     Vote results for this note: 1[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fwp%2F%23comment-4082)
 4.  This action will allow us to set a cookie in the headers but still have access
     to the WP class object. This example will show you how to set a cookie if you 
     are on a specific page ID.
 5.      ```php
         function wpdocs_set_cookie() {
           // using is_page conditional for specific page ID
           if ( is_page( 126 ) ) {
             setcookie( "wpdocs-my-custom-cookie", "true", time() + ( YEAR_IN_SECONDS * 5 ), COOKIEPATH, COOKIE_DOMAIN, false ); 
           }
         }
     
         add_action( 'wp', 'wpdocs_set_cookie' );
         ```
     
 6.   [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fwp%2F%3Freplytocom%3D4082%23feedback-editor-4082)
 7.   [Skip to note 4 content](https://developer.wordpress.org/reference/hooks/wp/?output_format=md#comment-content-7008)
 8.    [vee](https://profiles.wordpress.org/okvee/)  [  2 years ago  ](https://developer.wordpress.org/reference/hooks/wp/#comment-7008)
 9.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fwp%2F%23comment-7008)
     Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fwp%2F%23comment-7008)
 10. Please note that this hook is working only front pages or if there is WP query
     on the page (posts page).
 11. Normal admin pages such as admin > widget, this hook will never be called.
 12.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fwp%2F%3Freplytocom%3D7008%23feedback-editor-7008)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fwp%2F)
before being able to contribute a note or feedback.