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.

Can someone please tell me how to get the correct url of the page the user is on? I need to grab the url and construct a new link. Here is the issue that I am having. For example, let's say I am on http://localhost/myplugin/samplepage/?some_var=1&some_var=2

home_url() is http://localhost/myplugin
$_SERVER['REQUEST_URI] is /myplugin/samplepage/?some_var=1&some_var=2

As you can see, if I do this

$url = home_url() . $_SERVER['REQUEST_URI];

The outcome will be

http://localhost/myplugin/myplugin/samplepage/?some_var=1&some_var=2

Notice the 'myplugin' in the url twice, which doesn't work.

share|improve this question

1 Answer 1

up vote 2 down vote accepted

The built-in redirect_canonical() uses the following:

$requested_url  = is_ssl() ? 'https://' : 'http://';                                                                                                                                           
$requested_url .= $_SERVER['HTTP_HOST'];                                                                                                                                                       
$requested_url .= $_SERVER['REQUEST_URI'];
share|improve this answer
    
Thanks Adam. That did the trick. –  pistolshrimp Jan 21 '12 at 5:30

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.