• Victor

    (@victorstroe)


    Hi,

    To provide some background, I want to work on 2 domains:
    – live site, say – example.com,
    – admin domain, say admin.example.com

    The origin site is admin.example.com,
    and example.com is the live site
    (example.com synchronizes files periodically from admin.example.com)

    So the WP option for the site URL is x.com.

    I would like some help on the following:
    – when accessing the site with admin.example.com URL,
    I want the site to dynamically change links to comply with being on the admin.example.com site.

    Here’s an example:
    I go to example.com – I already have all links relative to example.com.
    I go to admin.example.com, I want all blog URLs to link up relative to admin.example.com, even tough the config site URL is example.com.

    admin.example.com is a hypothetical example, as I need to change hosts
    file entries and target example.com to admin.example.com IP for it to work.

    Do I have to do something more than change the site/admin URL using
    add_filter('site_url', 'custom_site_url') in the functions.php file?
    Does this affect any login cookies on the admin side?

    So besides changing the site_url with the filter, what should I do additionally in order for the site and admin to work with admin.example.com without changing the site URL config wide?

    Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • nickohrn

    (@nickohrn)

    Are these two separate WordPress installs entirely? Are you manually syncing the database between the two sites? When you reference wanting links to use the current host, do you mean generated links by WordPress, links in content, or something else?

    For what it’s worth, if you use relative URLs in content this won’t be a problem because it’ll use the current host to resolve the absolute URL. If you’re talking about generated links (for example, the output of the the_permalink) it really depends on your exact set up.

    My suggestion is to use the constants WP_HOME and WP_SITEURL in wp-config.php and set the correct value for each site. If you do this it no longer matters what site_url is set to in wp_options.

    Thread Starter Victor

    (@victorstroe)

    Hello Nick,

    Indeed, I am talking about WP generated URLs like permalinks, like a blogpost link shown on the homepage to an article, or to the admin section.(not manual or external URLs)

    I think your ideea with WP_HOME and WP_SITEURL would work for me like this:
    – on admin.example.com machine set an environment variable to flag it’s the origin
    – define the custom WP_HOME and WP_SITEURL if the above flag is set
    – do nothing on the replicas

    I’ll try to implement this tomorrow and post back,
    Thank you!

    Let us know if it works!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Dynamically change [site_url] depending on current URL’ is closed to new replies.