WordPress.org

Forums

Function Help: Home URL for Primary Domain and Sub-Domain (6 posts)

  1. pantone
    Member
    Posted 1 year ago #

    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.

  2. esmi
    Forum Moderator
    Posted 1 year ago #

    What is the correct way to achieve this?

    Via the Custom Url option in a custom menu.

  3. pantone
    Member
    Posted 1 year ago #

    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?

  4. esmi
    Forum Moderator
    Posted 1 year ago #

    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?

  5. pantone
    Member
    Posted 1 year ago #

    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.

  6. esmi
    Forum Moderator
    Posted 1 year ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic