Multi-Domains and WP Multi-Network / separate themes directory

Hello!

I use plugin Multi-Domains and WP Multi-Network. These plugins let me create other networks where I can use other domains. It works, but I have 1 problem:

I need to seperate themes directory. I'd like to have an other theme directory for every domain/network.

For now, every admin network has an access to all themes in themes directory.
I want to create networks for my clients, so there is no good situation.

Question: How in file .htaccess or wp-config add code like:

if domain1.com {themes directory = "themes1"}
if domain2.com {themes directory = "themes2"}

?

  • John
    • Design Lord, Child of Thor

    This code doesn't work. Can You check this?

    <?php
    /* Plugin Name: Local Theme Roots */
    
    if ( 'single.wp' === $_SERVER['HTTP_HOST'] )
        return;
    
    add_filter( 'theme_root_uri', 't5_switch_theme_root' );
    add_filter( 'theme_root',     't5_switch_theme_root' );
    
    /**
     * Create a custom theme directory.
     *
     * @wp-hook theme_root
     * @wp-hook theme_root_uri
     * author  Thomas Scholz, http://toscho.de
     * param   string $in URL or path
     * @return  string
     */
    function t5_switch_theme_root( $in )
    {
        // local multi-sites end with 'mu.wp'. Example: t5.mu.wp.
        if ( 0 !== stripos( strrev( $_SERVER['HTTP_HOST'] ), 'pw.um' ) )
        {
            return $in;
        }
    
        if ( 'theme_root_uri' === current_filter() )
        {
            return "http://themes.wp";
        }
    
        // If we made it so far we are in the 'theme_root' filter.
        $new_root = dirname( dirname( __DIR__ ) ) . '/wp-themes';
        register_theme_directory( $new_root );
        return $new_root;
    }
  • John
    • Design Lord, Child of Thor

    Hello! I found the better code :slight_smile:
    https://wordpress.org/plugins/multisite-themes/

    function multisite_themes() {
    
    	// get current site information
    	global $current_site;
    
    	// define multisite themes directory
    	$ms_themes = "ms-themes";
    
    	// add to wp-content directory
    	$dir = WP_CONTENT_DIR . "/" . $ms_themes;
    
    	// define index.php locations
    	$filename = $dir . "/index.php";
    	$filenamesite = $dir . "/" . $current_site->id . "/index.php";
    
    	// text for ms-themes index.php
    	$filetext = "<?php \n // Created using the Multisite Themes WordPress plugin \n ?>";
    
    	// get date and define text for site specific index.php with redirect
    	$date = date('l jS \of F Y h:i:s A');
    	$filetextsite = "<?php \n // Created: $date \n header('Location: http://$current_site->domain'); \n ?>";
    
    	// check if directory exists and create it if it does not
    	// add index.php file to the directory so it cannot be indexed
    	if ( ! is_dir($dir) ) {
    		mkdir($dir);
    		file_put_contents($filename, $filetext);
    	} elseif (!file_exists($filename)) {
    		file_put_contents($filename, $filetext);
    	}
    
    	// register theme directory for current site
    	register_theme_directory($dir . '/' . $current_site->id);
    
    	// create index.php in site folder for redirect and to prevent directory from being indexed
    	if ( is_dir($dir . '/' . $current_site->id) && !file_exists($filenamesite) ) {
    		file_put_contents($filenamesite, $filetextsite);
    	}
    }
  • Adam Czajczyk
    • Support Gorilla

    Hello Darek!

    The code from stackexchange seems to be "domain specific" so it should probably be tweaked a bit. The one you found looks much simpler though, thanks for sharing it :slight_smile:

    I understand it's working for you, is that right? If it's fine, it would be great if you could just mark this thread as resolved but if you still need assistance with it let me know please.

    Best regards,
    Adam

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.