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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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