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

How can I get the current path of my page?

I know how to do it inside a template file, but I need it inside functions.php. And it has to be before the send_headers hook, because I'll use this info to set a cookie.

I tried using PHP, but I'm getting /wp-admin

share|improve this question
Do you mean parse_url( $_SERVER['REQUEST_URI'] )? – toscho Apr 16 '13 at 10:28
Do you want to get path or URl of page? – Vinod Dalvi Apr 16 '13 at 10:29
//get page's path
$pagePath = parse_url( $_SERVER['REQUEST_URI'] );
$pagePath = $pagePath['path'];
$pagePath = substr($pagePath, 1, -1);//remove slashes

(a copy-and-past-ready answer adapted from Toscho 's comment)

share|improve this answer

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.