I am working on a custom theme and I have the following doubt about how to correctly insert the link to some section of my website into the theme.

If you open this link you can understand what I need to do: http://localhost/wordpressAsper/

As you can see under the header slideshow I have 3 boxes that are links.

I need to link the second box (the one named Archivio) to this page: http://localhost/wordpressAsper/archivio-2/

I know that I can simply put this URL into the href attribute of my a tag but this is not a smart idea because then I have to moove the website on my remote webserver.

So I am thinking that should exist something like a wordpress function to retrive the current URL of the website.

What is the best way to implement this thing?


  • 1
    Note that localhost simply points to your own computer. :) We won't see anything there (other than our own things :).
    – Rarst
    Aug 13, 2014 at 17:49

4 Answers 4


bloginfo('url') should get you the URL for the installation.


I guess you could also use get_permalink()

  • Note that this would return home URL, which is usually but not necessarily same as site URL.
    – Rarst
    Aug 13, 2014 at 17:48
  • You are correct but using that will take into account if core is installed in a sub-directory won't it?
    – Welcher
    Aug 13, 2014 at 17:56
  • Ehm, never mind... My brain wandered away into front page logic insanity. :) "home" would be correct for front-end URL here (and "site" for admin).
    – Rarst
    Aug 13, 2014 at 18:05
  • In special cases, such as, I'm using Polylang and when I visit a second language page bloginfo('url'); takes me to something like theurl.com/french. So using home_url() seems more robust.
    – Syed Priom
    Jan 15, 2016 at 19:38

As posed in question the way to retrieve the current URL to the root of the site would be home_url() for site's front-end.

However there are multiple functions that deal with URLs to specific kinds of pages. It's not clear what you are linking to (post? page? archive?), but there are likely specific URL-forming function for it which should be used over constructing such URL "manually" from the root address.


you can use bloginfo('url') but also can use get_option function, check documentation:


and by the way we cannot access your localhost :)


The global $wp object contains the current request, which can be used to get the current URL anywhere on the site. A helper function like the following demonstrates how this works:

function wp157715_current_url() {
    global $wp;
    $current_url = trailingslashit( home_url( $wp->request ) );

    return $current_url;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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