Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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
add comment

1 Answer

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 ...
});

Cheers!

share|improve this answer
    
Thanks, what does the list($uri, $qs) do? –  Wes 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 :) –  Wes Oct 21 '11 at 0:22
add comment

Your Answer

 
discard

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.