For the longest time, if someone wanted to have example.com, foo.example.com and example.com/bar for their Network on Multisite, I’d tell them to use a Multinetwork Plugin like Networks+ (which you can buy from e-Books by Ron and Andrea) or WP Multi Network (free from JJJ).
But sometimes you don’t need multiple networks and the multiple admin sections. Sometimes you just want to have options. Thanks to the work that started with the roadmap you can have your cake and eat it too.
If you’ll recall, I detailed how you can map a domain without a plugin on Multisite these days. Guess what? You can also do this with subfolders and subdomains.
I did this with a subdomain install, since it made more sense to go that way.
WordPress is installed at multisite.dev and I have subsites of foo.multisite.dev and bar.multisite.dev
I then made a new site called baz.multisite.dev:
Then I edited that from this:
To this:
Be careful here! If you don’t put the trailing slash on the folder name, this will not work. And does this work? Yes it does. Of course there is the small issue of how this looks on my list of domains:
I have two sites as ‘multisite.dev’ and I have two ‘foo’ sites (because you can also make foo.multisite.dev/zot if you want to). The problem is that the Sites page in the Network Admin has a check:
$blogname_columns = ( is_subdomain_install() ) ? __( 'Domain' ) : __( 'Path' );
This means the ‘domain’ of foo.multisite.dev/zot and foo.multisite.dev are (correctly) foo. I couldn’t see how to filter, so I made a quick MU Plugin:
class Add_Blog_Blogname { public function __construct() { add_filter( 'wpmu_blogs_columns', array( $this, 'blogname' ) ); add_action('manage_sites_custom_column', array( $this, 'blogname_columns' ) , 10, 3); add_action('manage_blogs_custom_column', array( $this, 'blogname_columns' ) , 10, 3); } function blogname_columns($column, $blog_id) { global $wpdb; $blog_details = get_blog_details($blog_id); if ( $column == 'my_blogname' ) { echo $blog_details->blogname; } return $value; } // Add in a column header function blogname($columns) { $columns['my_blogname'] = __('True BlogName'); return $columns; } } new Add_Blog_Blogname();
This tosses the True Blog Name to the end of the sites list. It’s not perfect, but it gets the job done.
Comments
5 responses to “Subdomains and Subfolders, One Network”
Nice writeup. Look forward to this being more seamlessly included in core in coming releases.
The potential trailing slash problem should be fixed in 4.2 at least!
My route:
My root domain is wordpress.hellyer.kiwi, which is a sub-folder install. This allows me to spawn new sites easily without dicking around with pointing any domains (I can’t do a wildcard at my domain registrar since I want to point various domains at different servers). Then when I want to use a sub-domain (ryan.hellyer.kiwi, geek.hellyer.kiwi etc.) I just map the domain on my sub-folder install.
@Ryan Hellyer: Yes but what if you want blog.hellyer.kiwi/tech as a separate sub-blog? That’s what this is good for π
@Ipstenu (Mika Epstein): I understand. I was just pointing out a shortcut for people wanting a simpler setup π
Huzzah! just what I have been after … thanks! π