0

I have a plugin that installs a folder of themes and other plugins into the WP site during plugin activation.

I would like to place script into the plugin which will activate one of the themes that the plugin installs.

Can someone post a quick example of script that registers and activates a known theme via a plugin's activation script?

1 Answer 1

2

switch_theme() should work:

function myplugin_activate() {
  switch_theme('default', 'default');
}

register_activation_hook( __FILE__, 'myplugin_activate' );
2
  • @OTP: The plugin actually copies the theme from one of its payload folders over into the themes directory during the plugin activation. Would there be any issues with the timing of the switch_theme() statement in relation to when the theme transfer is completed? ie, would it fail if the plugin has not yet transferred the theme fully into the theme's folder?
    – Scott B
    Mar 25, 2011 at 4:40
  • no, unless you're copying the files in the background with ajax and you don't wait for the response Mar 25, 2011 at 11:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.