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

1 Answer 1

// 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 ...


  • Thanks, what does the list($uri, $qs) do?
    – wesbos
    Commented Oct 20, 2011 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') Commented Oct 21, 2011 at 0:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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