WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to run a function that looks at the current url params of the page that is requested and sets a cookie based on those params.

So, I guess I'm looking for:

  1. The Wordpress Hook that allows me to do this before the page is even loaded
  2. A way to get the requested URL
share|improve this question
up vote 1 down vote accepted
// Kick in right before theme takes over, when WP is all loaded
add_action('wp', function(){
    list($uri, $qs) = explode('?', $_SERVER['REQUEST_URI']);
    // Do stuff here:
    // ... STUFF ...


share|improve this answer
Thanks, what does the list($uri, $qs) do? – wesbos Oct 20 '11 at 23:53
Extracts the URI and Query-String from current Request URI. (E.g.: domain.tld/uri?qs translates to $uri = '/uri' and $qs = 'qs') – EarnestoDev Oct 21 '11 at 0:20
Beaut, thanks :) – wesbos Oct 21 '11 at 0:22

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.