3

I am looking for a way to override the currently selected theme, preferably from within the wp_config.php file. I know you can override some wp_options settings in the config like

define('WP_HOME', 'http://someotherdomain.com');

This will override the 'home' option in the wp_options table. There is an option called 'current_theme' that stores the name of the currently selected theme. I'm wondering if there's a way to override this from the wp_config file and if so, will this actually change the theme.

I've tried

define('WP_CURRENT_THEME', 'someothertheme');

but it doesn't work.

I need to do this in our development environment because the database is shared among two developers. I need to be able to work on one theme, while the other developer works on another theme.

  • Shared database == same database? Same domain? Same WordPress files? Based on what this switch should occur? – brasofilo Jul 19 '12 at 15:40
  • brasofilo, same database, different wordpress files. The code to switch the theme would just be temporary, in order to develop two different themes at the same time. One developer would use the database setting, the other would override the settings in wp_config. – joeljoeljoel Jul 19 '12 at 15:49
5

Drop this in a plugin & activate. I should note this doesn't take into account things like child themes - it's purely for toggling which theme renders based on SOME_FLAG.

add_filter( 'stylesheet', 'switch_ma_theme' );
add_filter( 'template',   'switch_ma_theme' );

function switch_ma_theme()
{
    // Return the theme directory name
    return SOME_FLAG ? 'theme-1' : 'theme-2';
}
| improve this answer | |
1

Another solution.

add_action( 'template_redirect' , 'thisismyurl_change_theme_manually' );

function thisismyurl_change_theme_manually() {
if ( 'twentyeleven' != get_stylesheet() && is_admin() )
switch_theme( 'twentyeleven', 'style.css' );
}

But if your using different WordPress installs why don't you just click "activate theme" in the admin?

ps. You can read more here: http://nacin.com/2012/03/29/page-templates-in-subdirectories-new-in-wordpress-3-4/

| improve this answer | |
  • I'm using different WordPress installs but the same database. If one developer changes the theme in the admin, it will change for both developers – joeljoeljoel Jul 19 '12 at 16:09
  • You should not share a database, you're going to run into a lot more problems then setting themes. – Wyck Jul 19 '12 at 16:11
  • We share a database in our development environment. See viastudio.com/2011/02/08/… if you're interested in how to set up with out having problems. – joeljoeljoel Jul 19 '12 at 16:31
  • 2
    And how to you preserve database entries....sharing a database is easy, sharing WordPress content/id's/variables stored in the DB is not. – Wyck Jul 19 '12 at 17:09
1

When you are sharing same database with different installs of wordpress having, then best solution is to add theme information in config file only because if you go to admin and change theme, it will change theme for all installs of wordpress sharing same database.

You can add following code to your wp-config.php file:

define('TEMPLATEPATH', '/path/to/your/new/theme/directory');
define('STYLESHEETPATH', '/path/to/your/new/theme/directory');
| improve this answer | |
0

Why not use a plugin like WordPress › Theme Tester « WordPress Plugins or similar and have the devs use different admin logins? Not sure if Theme Tester handles widget selections, though.

And it's still not a good idea to use one DB for two installs.

| improve this answer | |

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.