Sign up ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

1 Answer 1

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