Change the default theme for sites without a plugin

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.

  • David Gilmour
    Posted at 10:10h, 19 July Reply

    Thanks Andrea, I’d been wondering!

  • asshu
    Posted at 12:20h, 20 July Reply

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

    • andrea
      Posted at 12:29h, 20 July Reply

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

  • asshu
    Posted at 12:47h, 20 July Reply

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

    • asshu
      Posted at 12:53h, 20 July Reply

      I think “YD Network-wide options” is a cause for this error.

  • Philippine Outsourcing
    Posted at 00:30h, 22 July Reply

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

  • asshu
    Posted at 14:56h, 28 July Reply

    I am getting a blank page If I try any of these themes other than classic .

    Could you tell me where I am missing?

    • Ron
      Posted at 21:36h, 28 July Reply

      You use the name of the folder that the theme is in as opposed to the name of the theme.

      • asshu
        Posted at 22:15h, 28 July Reply

        Thanks a lot ! It worked for me.

  • trikon
    Posted at 12:44h, 09 December Reply

    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?

    • Ron
      Posted at 16:26h, 09 December Reply

      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.

      • trikon
        Posted at 02:40h, 13 December Reply

        What you think about this func?

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

        • andrea
          Posted at 11:59h, 13 December Reply

          Why rewrite a function that wordpress gives you?

  • Rémi
    Posted at 11:53h, 13 December Reply

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

    • andrea
      Posted at 11:58h, 13 December Reply

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

  • Clifford
    Posted at 09:30h, 17 December Reply

    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.

  • Clifford
    Posted at 09:41h, 17 December Reply

    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’);

    • andrea
      Posted at 10:11h, 17 December Reply

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

      Anything *under* that line? Will cause issues.

  • Ed
    Posted at 07:11h, 06 January Reply

    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?

    • andrea
      Posted at 09:38h, 06 January Reply

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

      • Ed
        Posted at 17:22h, 06 January Reply

        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 🙁

        • andrea
          Posted at 17:51h, 06 January Reply

          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.

          • Ed
            Posted at 17:28h, 08 January

            Thanks Andrea!

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

          • Ed
            Posted at 17:28h, 09 January

            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!

  • Jay
    Posted at 12:51h, 19 January Reply

    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.

  • andrea
    Posted at 15:18h, 19 January Reply

    “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.

    • jay
      Posted at 01:13h, 20 January Reply

      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.

    • jay
      Posted at 01:35h, 20 January Reply

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

      • andrea
        Posted at 19:45h, 22 February Reply

        Because you;re using different themes. This is if you use the same parent on ALL sites.

  • NrFive
    Posted at 20:05h, 21 January Reply

    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/’);

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

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

    • andrea
      Posted at 13:04h, 22 January Reply

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

      You have it set to twentyten is why.

    • andrea
      Posted at 19:42h, 22 February Reply

      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.

  • venu
    Posted at 07:11h, 19 February Reply

    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’);

    • Ron
      Posted at 11:26h, 19 February Reply

      This doesn’t work with child themes.

  • Jason Ulrich
    Posted at 17:00h, 22 June Reply

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

Post A Comment