Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question
    
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
add comment

1 Answer

up vote 2 down vote accepted

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' );
}
share|improve this answer
    
I can't test this because we have gone a different direction with the blog. I used the solution from here in combination with only one subdomain. wordpress.stackexchange.com/questions/13411/… –  mrtsherman Apr 5 '11 at 17:35
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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