2

I've got a site that I'm trying figure out how to apply different child themes to based on a subdomain. Applying the child themes shouldn't be difficult, it's more the .htaccess magic that I'm a bit iffy on.

What I'm after is a site that has say:

example.com/red/
example.com/blue/

Where red and blue are different child themes. But all links can still be accessed as:

example.com/red/blog/
example.com/blue/blog/

Multisite seems like overkill to me, as the sites would have the exact same content, with different style sheets, and different images. I'm thinking that perhaps add_rewrite_rule() would be more appropriate for this situation. But regex is latin to me.

  • What is the reason for this? Is it a way for people to switch themes or to preview a theme? – Seamus Leahy Sep 16 '14 at 6:06
  • It's by request of the client. He's been made aware of search engines having issue with duplicate content, however he wants it to look like there are multiple sub sites for whatever reason. Even tho said sub sites will have nearly identical content, except for a few images and their style sheets. – r0tterz Sep 18 '14 at 2:30
  • Here is the solution: Just install the plugin there is setting under appreance wordpress.org/plugins/subdomain-theme-switch – Bijaya Kumar Oli Apr 11 '15 at 3:41
1

I'd encourage you to take one step further back and avoid using URLs to determine theme at all. (And FYI, what you're describing are subfolders, not subdomains which would be red.example.com.)

The reason not to do this is to avoid duplicate content issues with search engines. Technically, you could work around them, but it can also be confusing to visitors who reasonably expect different URLs to load different content.

Instead, I'd encourage you to look into a "theme switcher" plugin. I'm not familiar with any of them but here are some to get you started:

If it were me, I'd carefully look at using localstorage to conditionally load a specific "skin" stylesheet that only includes the color changes it seems like you want.

  • localstorage is a possibility, if I was after an invisible solution. However client wants to see it in the URL. I'm wondering if there's possibly some kind of .htaccess stuff I could use to turn example.com/blog?site=blue into example.com/blue/blog ? – r0tterz Sep 18 '14 at 2:33
  • Check out add_rewrite_rule(). – mrwweb Sep 18 '14 at 3:30
0

I do agree with mrwweb about duplicate content, I'm not quite sure why you'd want to do that, but, for the sake of argument...

You could possibly grab the URL and then enqueue the correct style sheet from your functions.php

Something like this (untested):

<?php
    function mytheme_stylesheet_enqueue(){        
        global $post;
        $my_url = get_page_link($post->ID);
        if (strpos($my_url,'red') !== false) {
            wp_register_style( 'red-stylesheet', get_stylesheet_directory_uri() . '/red-style.css', array(), '', 'all' );
            wp_enqueue_style( 'red-stylesheet' );
        }
        if (strpos($my_url,'blue') !== false) {
            wp_register_style( 'blue-stylesheet', get_stylesheet_directory_uri() . '/blue-style.css', array(), '', 'all' );
            wp_enqueue_style( 'blue-stylesheet' );
        }
    }
    mytheme_stylesheet_enqueue();
?>
  • It's not the stylesheets that I'm having an issue with. I can get those to switch easy enough. It's more the URL, I'm wondering if there's possibly some kind of .htaccess stuff I could use to turn example.com/blog?site=blue into example.com/blue/blog – r0tterz Sep 18 '14 at 2:34
  • What is the user going to get as a url to enter the site, and how do you plan on switching between red and blue once the user is on the site? Is the user going to have a theme switcher of some sort or will links just lead to pages with different colors? – Rob Sep 18 '14 at 3:01
  • so user would enter site via example.com, and from there they would see links on the side bar to 'site1' 'site2' or 'blue' 'red' if I'm continuing my example. Once user clicked on one of those links they would then be sent to example.com/red or example.com/blue which would swich either the style to red.css or blue.css or the child theme. Which ever. From there the user can navigate through the menu to example.com/red/blog and example.com/blue/blog. – r0tterz Sep 18 '14 at 3:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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