1

I have my blog under blog.mydomain.com. I am using pages for some static content that needs to be accessed from another subdomain. So careers.mydomain.com will show WordPress content from blog.mydomain.com/careers.

My problem is that all the links on the page still reference blog.mydomain.com. Is there a way to ask WordPress to use relative links? Or a way to change the baseURL for pages?

  • wordpress.org/extend/plugins/wordpress-subdomains There's an (outdated) plugin. Maybe the code will help at least, if it doesn't work..... – Rev. Voodoo Mar 29 '11 at 19:40
  • Do you have proxy module available in your webserver? I know a solution, if you have. – petermolnar Apr 1 '11 at 8:38
  • @cadeyrn We run our own server so we could install a proxy module if necessary. – mrtsherman Apr 1 '11 at 14:04
2

There is a filter, post_link, that permalinks pass through before being returned from get_permalink in wp-includes/link-template.php. You can use that filter to alter the links.

However, beware that making all permalinks relative may have unintended consequences in certain contexts, e.g. you might not want relative links when is_feed() == true.

You may find that the post_link filter doesn't catch all of the URLs you need changed. In that case, you can try the home_url filter which has much broader effect.

Another possibility (my favorite) is to use output buffering to relativize the links. (Example at bottom.)

To be safe, you can change the links only when necessary. I don't know how you're getting the content from the actual blog to the static subdomain, but if you're using HTTP requests you can add a query arg: ?rlz and then look for that in your theme/plugin.

if ( isset($_GET['rlz']) ) {
    function my_ob_handler($HTML) {
        return str_replace( home_url('/'), '/', $HTML );
    }
    ob_start( 'my_ob_handler' );
}

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.