Changing a live theme directory name

Now this is definitely NOT a WPMUDEV issue, but an appeal to fellow advanced multisite techies for advice in how to get out of this hole!

The situation is one of my inhouse created themes (lets say xyz-theme) has the same name as a third party theme that we want to use on the multisite.

Whats the issue just change the name of the inhouse theme directory and the name in the top of the style.css and move on?

Well, when you change the theme directory (e.g. 123-theme)the site flips over to the default theme, when you add the newly named theme 123-theme back to the sites the sidebars and menus are all defaulted too! Not a pretty sight in test.

Also very manual re-setting the theme on many sites.

Any ideas. e.g. stop the flip to default (does pro-sites do that flip?), what actually actions the flip - if no visitors can the flip be stopped? What about bulk adding back the theme?

Or am I going about this a very hard way and there is a better approach?

My multisite isn't massive but beyond manual changing of all sites and also need to test any approach carefully before breaking the live system.

  • Patrick

    Hi @llocally

    If you change the theme folder name (and the name in style.css of course), then WordPress thinks it's a different theme... which it is. :slight_smile:

    So yes, you would need to enable that new theme, and activate it on all sites where you want it.

    As for the theme defaulting to the default theme, that is normal WordPress behavior when an active theme suddenly becomes inactive.

    So I think the only way to prevent WP from flipping to the default theme is to upload and network-enable your modified in-house theme as a new theme. Then activate it on those sub-sites.

    Hopefully, as the sidebar names will remain the same, the widgets should stay put. I'd check 'em all anyway just to be safe.

  • Fullworks

    Good thinking Patrick. I'll test that approach, sidebars should be OK, although have feeling menus might be an issue.

    Also I'm thinking the wp config `define('WP_DEFAULT_THEME', '123-theme'); might well be useful.

    So
    - duplicate xyz-theme into 123-theme and change style.css name (so you can tell them apart)
    - set wp config WP_DEFAULT_THEME to 123-theme
    - delete xyz-theme
    - it flips to 123-theme, maybe without going through every site
    - reset the default theme
    hopefully sidebars & menus in tact

    Worth testing it, I would say.

  • Imperative Ideas

    Let's say I have a theme called "Blue", it's header looks like this:

    /*
    Theme Name: Blue
    Theme URI: http://imperativeideas.com
    Description: This theme is the color of the sky
    Author: Ian Armstrong
    Author URI: http://imperativeideas.com
    Version: 3.0
    License: GNU General Public License v2 or later
    License URI: http://www.gnu.org/licenses/gpl-2.0.html
    */

    So I go and change the name to Purple, because a new "blue" has been imported.

    Now, let's say I had set 13 font colors, my social media names, and a few other things in the theme options panel... but I've changed the name of the theme now so WordPress has no idea where any of those settings are.

    Bam, blank slate.

    Users will be peeved.

  • Fullworks

    I see waht you men, I am ok on this as I coded my theme options with a 'hard coded' name in the set/get options, in the same way that the default themes (2011-12-13) are coded.

    This means that the stylesheet 'Theme Name' will have no impact on the theme options that will remain 'safe' in the database.

    I can't see the possibility in your issue occurring in themes where the option group name is not hard coded, where the Theme Name is derived dynamically from the stylesheet by a call to wp_get_theme( ), but actually I don't think I have seen a theme coded that way.

    The issue I will have is that I can risk the two theme being active in the same blog, as their 'option' group names will be the same and they could easily cause unexpected behaviours in each other, but fortunately I don't need the two active in the same blog. Although I could write some code to 'transfer' options easily enough.

    I do thank you for your input, but I think I will be OK, but of course I will test carefully.

    ... edit ....

    Actually, I think there is an issue as core wordpress features like background use set/get_theme_mod() which I think does use the stylesheet name. I'm going to have to read the WordPress code.... but I am devising a plan - it is ore complex and it will require some conversion code ...

  • Fullworks

    OK

    enhanced plan

    write code that copies the theme options across and duplicates them under the new name
    covering both
    option "theme_mods_newtheme" (for theme_mods wordpress uses)
    and the option coded in my theme options (which I know what they are :slight_smile: )

    and stick this code in the functions.php of the old theme and visit all sites, hence duplication all options and theme options

    take the old theme and change ALL of its name references (including options) (but not sidebars or menus)

    Install new theme next to old theme

    set wp default theme to new theme

    delete old theme

    visit all sites to change to default

    hey presto

    if that works, well I'd be surprised, but pleased

    got some coding to do now :slight_smile:

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.