Change the default theme for sites without a plugin





There’s a new and very little documented feature in 3.0 for changing the default theme. And? This will work on single WordPress installs as well as being handy for a network of sites.

The magic line is this in your config file:

define('WP_DEFAULT_THEME', 'theme-folder-name');

In this example, the classic theme is used as the default when a site is created, or when a theme in use is removed. If you are starting fresh with 3.0, the default is the new TwentyTen, so this override is handy.

Added tip: if you have a lot of blogs using the Kubrick theme and wanted to remove it and set the other blogs, do this define first with your new default theme, then remove or rename the Kubrick theme folder (in my it was simply “default”). On a refresh, all blogs using the Kubrick theme will be switched to your new default.

If you just wanted the Kubrick theme to go away and have twentyten show up, you won’t need to do the define above. Just rename the /default/ theme folder. It’ll kick in.

(thanks to Ron for reminding me & MichaelH for the codex note I missed)

EDIT: if you are setting a CHILD THEME as the default, you’ll get some errors. Place this line in your wp-config.php file as well, right under the line I gave above.
define( 'TEMPLATEPATH', '/path/to/themes/folder/name-of-parent-theme');

Further amendment: if you really want a child theme set as default, but still have the ability to switch to other theme (standalone or child of another parent) then you will HAVE TO use a plugin to set the default theme.

35 Comments

  1. Thanks Andrea, I’d been wondering!

  2. I tried the code.But nothing is changed. The same “TwentyTen” .

    • Do you have any plugins running like New Blog Defaults? Also, it does not change the theme on all blogs by itself.

  3. I don’t have the plugins like “New Blog Defaults” .But I installed plenty of plugins of different kinds.

  4. Philippine Outsourcing
    Philippine Outsourcing

    Thanks for this … I’ve been searching in the wrong places and thought it was part of the control panel … Andrea rocks indeed!

  5. I am getting a blank page If I try any of these themes other than classic .
    Overdose40
    Mystique
    ChocoTheme
    WordPraized

    Could you tell me where I am missing?

  6. and what about redefine this constant ‘WP_DEFAULT_THEME’ ?
    Maybe with some hooks – actions or filters. It’s not a good idea to change core, or am i wrong?

    • Constants are so named that they cannot be redefined. Most constants in WordPress exist for the purpose of the site owner defining them. Defining a constant does not change WordPress core.

      • What you think about this func?

        function change_default_theme($blog_id) {
        switch_to_blog($blog_id);
        switch_theme(‘yourTheme’, ‘yourTheme’);
        update_option(‘current_theme’, ”);
        restore_current_blog();
        }
        add_action(‘wpmu_new_blog’, ‘change_default_theme’, 100, 1);

  7. Thanks for this easy trick.
    Was in default-constants.php

    • Yes, that’s where WP stores the internals. DO NOT edit that file. Place the constant in wp-config like the post above specifies.

  8. adding this to wp-config.php doesn’t work (I tested it with WP 3.0.3 running multisite WP) but changing the wp-includes/default-constants.php work.

    I don’t know why that happen.

  9. I know what happen. Just figured it out now. The code must be place above the absolute path for wp-settings.php so that it will get executed first before it goes to default-constants.php

    define( ‘WP_DEFAULT_THEME’, theme-folder-name’ );
    require_once(ABSPATH . ‘wp-settings.php’);

    • Becasue ypou placed the code *below* the ”
      /* That’s all, stop editing! Happy blogging. */” line.

      Anything *under* that line? Will cause issues.

  10. Great tip Andrea!

    I am getting some white screens on sites that where created when there was a different theme. If I go into it and click themes, it says
    “The active theme is broken. Reverting to the default theme.” then it works. But I don’t want to have to do this manually as there are hundreds of them.

    any ideas?

    • Is it a child theme you’ve set to default?

      • No. it has child theme funtionallity but I didn’t buy the child themes. It’s called heatmap theme and it has a preset mode that is set to on so it loads all the options from a php file instead of having to enter it in on the options page for every site.

        I did a full refresh/update and some of the sites work that were created with a “default” named template but others that were created with another named template are white screens.

        I can fix them manually by running these SQL commands on each table/site (where 1 refers to the number of the site):
        UPDATE wp_1_options SET option_value = ‘default’ WHERE option_name = ‘template’
        UPDATE wp_1_options SET option_value = ‘default’ WHERE option_name = ‘stylesheet’
        UPDATE wp_1_options SET option_value = ‘default’ WHERE option_name = ‘current_theme’

        I wish there was a faster way 🙁

        • A white screen means it’s a php error. Always. Check your logs. 😉

          I’m 90% certain it’s got something to do with your theme, especially if it fires an activation hook when the user activates the theme.

          • Thanks Andrea!

            I think your right. I have some definite errors here. Hopefully if I fix them they will refresh correctly. Thanks again

          • Hi Andrea,

            I fixed all the errors and still no luck. 🙁 I changed the dir of the template to narrow it down, as well as the plugins so I am pretty sure it’s the database now. I looked in one of the wp_*_options tables and it says twentyten in the template area on the white screen blogs. I am willing to try anything at this point!

  11. Sorry I can’t seem to get this to work. I am running the latest WP and BP versions. My main blog is using a child theme of bp-default and I want all sub blogs to use a child theme of twenty ten.

    When I add the following my main blog gets a white screen.

    define(‘WP_DEFAULT_THEME’, ‘twentyten-child’);
    define( ‘TEMPLATEPATH’, ‘/wp-content/themes/twentyten’);

    For the first line, Am I supposed to add the default theme of my main blog or the default theme I want to use for new sub blogs? I’m sure its the new default theme for sub blogs.

    For the second line, is this the path of the parent theme of the child that I want to use as the default theme?

    I have to be over-thinking this.

  12. “define( ‘TEMPLATEPATH’, ‘/wp-content/themes/twentyten’);”

    This needs to be the full server path, so /public_html/wp-content/themes/twentyten or whatever applies.

    just keep going up till it finds it.

    • This simply doesn’t work. If I set the TEMPLATEPATH to my twentyten child theme it changes my main blog (my BP blog) but subblogs work. If I change TEMPLATEPATH to point to BP-Default my home page works but then sub blogs dont.

      I don’t have any errors. I have spent a couple hours trying to figure out what im doing wrong.

    • I confirmed I am using the correct path for the templates. As soon as I change set TEMPLATEPATH to anything my main blog changes.

  13. Trying to achieve the default theme for newly created blogs.

    Added this to my wp-config file:

    define(‘WP_DEFAULT_THEME’, ‘twentyten’);
    define( ‘TEMPLATEPATH’, ‘/customers/gameshrine.org/gameshrine.org/httpd.www/wp-content/themes/fishbook-buddypress-buddypack’);

    Yet no results… can’t figure out what is going wrong here…

    Currently checking my php logs to see if I can fix anything.

    • “define(‘WP_DEFAULT_THEME’, ‘twentyten’);”

      You have it set to twentyten is why.

    • Also – extra blogs in the network DO NO need to use a buddypress theme. you only need a BP theme on the blog where BP is home.

  14. I think the problem is on my end.When I am trying any other parent theme as default theme.The newly created sub-sites are showing an error

    I could not able to replicate the problem.I followed exactly as explained

    define(‘WP_DEFAULT_THEME’, ‘mytheme’);

  15. Thank you so much. Especially for the edit about child themes. Worked perfectly.

Leave a Reply to RonCancel Reply