WordPress.org

Support

Support » How-To and Troubleshooting » Function Help: Home URL for Primary Domain and Sub-Domain

Function Help: Home URL for Primary Domain and Sub-Domain

  • I have a question regarding WordPress functions as it relates to “home_url” for a primary domain and sub-domain.

    Let’s say I have a blog on a sub-domain at “blog.domain.com”. On “blog.domain.com”, I have a “Home” text link in the navigation menu that I want to hyperlink to the homepage of the primary domain “domain.com”. What is the correct way to achieve this?

    If I use the function “home_url” on the sub-domain, it will hyperlink to “blog.domain.com”, which is not what I want. Is there a function that will link it to the primary domain?

    Thanks.

Viewing 5 replies - 1 through 5 (of 5 total)
  • esmi
    Forum Moderator

    @esmi

    What is the correct way to achieve this?

    Via the Custom Url option in a custom menu.

    Thank you for the resource!

    So rather than using a function, I can simply enter a custom URL in the custom menu?

    Out of curiosity, though, is there a function that would also allow me to link to the homepage of the primary domain from the sub-domain?

    esmi
    Forum Moderator

    @esmi

    So rather than using a function, I can simply enter a custom URL in the custom menu?

    Ideally, yes as this would make the theme far more portable across multiple domains/sites. Is there any reason why you would particularly want to hard code it into a menu?

    Thank you for clarifying. The only reason is actually because I thought hard coding it using a WP function was the “best practice” way of doing it.

    I will be using the custom menu, though. Thank you again.

    esmi
    Forum Moderator

    @esmi

    There isn’t any way to “code” the url of another, unconnected, WordPress site into your current site. Even though both sites are using the same basic domain name, they’re still, essentially, separate sites. So you would, literally, have to hard code the url of the site into the theme’s template file – which isn’t always ideal.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Function Help: Home URL for Primary Domain and Sub-Domain’ is closed to new replies.