how to use a different domain/subdomain for authors/catagories on single site?

I’m not sure if I phrased this question correctly…

My wife and I have one blog, in this example, that we both contribute to.

I would like to show all blog posts. would show only posts I author and would show only posts she authors. later, we will add and so on…

further, sometimes she/I/we do projects that grow beyond one post. would show only all posts in the ‘project1’ category. However, unlike authors, only specific categories would have their own domain names.

wp-subdomains-revisited plus domain-mapping-system used together seem closest to what I am looking for but they’re outdated and I’m sure I couldn’t replicate them myself.

Edit 1: I found this wonderful answer by mikeschinkel: Multiple Domain Names – One WP Install (non-Multisite) – Default Each Domain name to Category Archive

Edit 2: I got mikeschinkel’s code working on my site. Great! Now, I’ve been trying to modify it to work with subdomains as well. That has not gone so well – only a white page loads when my modifications are in place.

Edit 3: The site is loading again with working domains and subdomains! How exciting!

Next task is to have all links use their respective domain/subdomain. For example, a post holiday written by me and in category project1 should appear as, or depending on which sub/domain it’s linked from. Any suggestions would be wildly appreciated!!!

(also, it will have to work with WPML ->, when translated, should becomeδΌ‘ζ—₯/ … frightening!)

Edit 4: Just to clarify, functionally this should be no different than viewing an individual author or category archive, the only difference being the archive will have it’s own sub/domain.

Also, my TLD is .is… and my domain is my family name. That means my URL is halfway to being a sentence ->…

The goal is to have a url specific to whatever relationship:

Edit 5: Updated code – mostly working now. I’m reluctant to mark it as solved because I haven’t removed the base category or added separate header/title for each page… but as is this code works and solves the main question of the post. I hope someone else finds it useful πŸ™‚

Edit 6: I found a nice plugin called wp-no-base-permalink which removes the category base. I updated the code to work with this plugin. Now if I type it shows all uncategorized posts by me – exactly what I was looking for!

answer below…

Solutions Collecting From Web of "how to use a different domain/subdomain for authors/catagories on single site?"

Is there some reason you need subdomains over “subdirectories” (I put that in quotes because it won’t actually be a real subdir… read on)? This would be much easier if you wanted to go with,,, etc…

Going this route, you could create page templates that have custom loops in them using WP_Query and assign them to pages in the WP Admin. If you’re using pretty permalinks, then you can name the page whatever you want and you’ll have a nice looking link.

I honestly can’t think of a way this would be possible with subdomains, but that’s less of a WP question and more of a domain/server management question.

The best way to achieve content separation between sites is to separate their DBs. As a rule of thumb it is easier to aggregate content the separate it, search, RSS feeds, social sharing, SEO might need to behave differently on different subdomain, and there is no way the kids will agree to the design imposed by the “old guys”.

The easiest solution is to use wordpress in a network mode, and then wherever you need write or find a plugin that will automatically import content from the “source blog” to the right aggregation site.


if ( is_alt_domain( $_SERVER['SERVER_NAME'] ) ) {
    $domain = str_replace( 'www.', '', $_SERVER['SERVER_NAME'] );
    define( 'WP_SITEURL', 'http://www.' . $domain );
    define( 'WP_HOME', 'http://www.' . $domain );
} else if (is_sub_domain( $_SERVER['HTTP_HOST'] ) ) {
    $domain = "{$_SERVER['HTTP_HOST']}";
    define( 'WP_SITEURL', 'http://' . $domain );
    define( 'WP_HOME', 'http://' . $domain );
} else if (! (is_main_domain( $_SERVER['SERVER_NAME']) ) ) {
    Header( "HTTP/1.1 301 Moved Permanently" );
    Header( "Location:", true, 301 );
function is_main_domain( $domain ) {
    $domain = $_SERVER['HTTP_HOST'] ;
    return strcmp( $domain, my_main_domain() ) == 0 ;
function is_sub_domain ( $domain ) {
    $domain = str_replace( my_main_domain(), '', $_SERVER['HTTP_HOST'] );
    return in_array( substr( $domain, 0, -1), sub_domains() );
function is_alt_domain( $domain ) {
    $domain = str_replace( 'www.', '', $_SERVER['SERVER_NAME'] );
    $domain = substr( $domain, 0, strrpos( $domain, '.') );
    return array_key_exists( $domain, alt_domains() );
function sub_domains() {
    return array(
function alt_domains() {
    return array(
        'project1' => 'com',
        'project2' => 'com',
        'project3' => 'is',
function my_main_domain() {
    return '';


// this seems to be important
update_option('siteurl','http://' . $_SERVER["HTTP_HOST"]);
update_option('home','http://' . $_SERVER["HTTP_HOST"]);

add_action( 'category_link', 'yoursite_category_link', 11, 2 );
function yoursite_category_link( $category_link, $category_id ) {
    $parts = explode( '/', $category_link );
    // if %category% in http://%domain%/%category%/
    // is in alt_domains() update the category_link
    if ( array_key_exists("{$parts[3]}", alt_domains() ) ) {
        $tld = alt_domains()[$parts[3]];
        $category_link = "http://www.{$parts[3]}.{$tld}/"; // Strip 'category/%category%/'
    return $category_link;

add_action( 'author_link', 'yoursite_author_link', 11, 2 );
function yoursite_author_link( $author_link, $author_id ) {
    $parts = explode( '/', $author_link );
    // if %author% in http://domain/author/%author%/
    // is in sub_domains() update the author_link
    if ( "{$parts[3]}" == "author" && in_array("{$parts[4]}", sub_domains() ) ) {
        $author_link = "http://{$parts[4]}"; // Strip 'author/%author%/'
    } else {
        $author_link = "{$parts[4]}"; // Strip 'author/%author%/'
    return $author_link;

add_action( 'init', 'yoursite_init' );
function yoursite_init() {
    // Remove the canonical redirect to the category page
    // if %category% in http://%category%.%ext%/ is a blogger category
    if ( is_alt_domain( $_SERVER['SERVER_NAME'] ) || is_sub_domain( $_SERVER['HTTP_HOST'] ) ) {
        $parts = explode( '/', strtolower( $_SERVER['REQUEST_URI'] ) );
        if ( (count($parts) > 1) &&  ( array_key_exists("{$parts[1]}",alt_domains() ) || ( "author" == $parts[1] && in_array("{$parts[2]}", sub_domains() ) ) ) ) {
            remove_filter( 'template_redirect', 'redirect_canonical' );

add_action( 'template_redirect', 'yoursite_template_redirect' );
function yoursite_template_redirect() {
    // Redirect any http://%domain%.%ext%/%category%/ to http://%category%.%ext%/
    // and any http://%domain%.%ext%/author/%author%/ to http://%author%.%domain%.%ext%
    $parts = explode( '/', strtolower( $_SERVER['REQUEST_URI'] ) );
    if ( array_key_exists( "{$parts[1]}", alt_domains()) ) {
        $tld = alt_domains()[$parts[1]];
        wp_redirect( "http://www.{$parts[1]}.{$tld}/", 301 );
    } else if ( 'author' == $parts[1] && in_array("{$parts[2]}", sub_domains() ) ) {
        wp_redirect( "http://{$parts[2]}", 301 );

add_action( 'request', 'yoursite_request' );
function yoursite_request($query_vars) {
    // If %category% in http://%category%.%ext%/ is a blogger category set the
    // 'category_name' query var to tell WordPress to display the category page.
    if ( is_alt_domain( $_SERVER['SERVER_NAME']) || is_sub_domain( $_SERVER['HTTP_HOST'] ) ) {
        $category_domain = str_replace( 'www.', '', $_SERVER['SERVER_NAME'] );
        $category_domain = substr( $category_domain, 0, strrpos( $category_domain, '.' ) );
        $author_name = substr( $_SERVER['HTTP_HOST'], 0, strpos( $_SERVER['HTTP_HOST'], '.' ) );
        $parts = explode( '/', $_SERVER['REQUEST_URI'] );
        $category_name = "{$parts[1]}";
        if ( array_key_exists($category_domain, alt_domains()) ) {
            if ( strlen( $category_name ) < 1  ) {
                $query_vars = array( 'pagename' => $category_domain.'-page' );
            } else if ( term_exists("{$category_name}", 'category') ) {
                $query_vars = array(
                    'category__and' => array(
        } else if ( in_array( $author_name, sub_domains() ) ) {
            if ( strlen( $category_name ) < 1  ) {
                $query_vars = array( 'pagename' => $author_name.'-page' );
            } else if (term_exists("{$category_name}", 'category') ) {
                $query_vars = array(
                    'category_name' => $category_name,
                    'author_name' => $author_name
    return $query_vars;

And, of course, you also need to point your subdomains (or *) on your nameserver to your wordpress install. You also will need to add a Virtual Host (Nginx) for any other domains you are using… and you will need to set up CORS.

As a side note, this answer used in conjuction with my next answer/question – How to have a static category/author page? – should make my intentions of having one multi-faced site a little more clear πŸ™‚

Admittedly a clever solution, and one that works fine within the scope of your original question. For future readers with similar use cases’ reference though I would suggest they also consider creating a multisite (network) install.

When used purely for sub domain sites (ie no domain mapping) it’s not greatly more difficult to create and manage than a standard install. You then have a far wider scope to develop each sub site as you like in the future, and much more flexibility (entirely different themes etc.). Not to mention a more logical and easy to manage arrangement of content. Multisite is also far more extensible – add domain mapping and you can add your business site, other friends, sports groups etc on the one hosting account and admin log on.

The ThreeWP Broadcast plugin is a great solution for publishing posts on whatever sites are suitable for the topic etc, and some background reading on that will demonstrate the scope of multisite.

Just my feeling that most traffic to this post (due to the title) in the future will be people for whom multisite is a good fit but one that’s often overlooked.