Relative instead of absolute links in pages?

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

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

Solutions Collecting From Web of "Relative instead of absolute links in pages?"

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' );