0

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?

Tnx

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

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

EDIT:

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 '14 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 '14 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 '14 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 '16 at 19:38
1

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.

0

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

http://codex.wordpress.org/Function_Reference/get_option

and by the way we cannot access your localhost :)

0

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, privacy policy and cookie policy

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