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.

4 Answers
4

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';
}

Leave a Reply

Your email address will not be published. Required fields are marked *