Is there a method that exists that will let me switch the theme?

It looks like switch_theme is the method and there is also an event of the same name. It says that it accepts an argument of stylesheet and for backwards compatibility it accepts, $themename and $stylesheet. I guess I don't understand, why is someone changing the stylesheet and no longer changing the theme?

  • 1
    switch_theme? – Milo Nov 6 '15 at 22:00
  • 1
    Assuming you mean programmatically? – jdm2112 Nov 6 '15 at 22:06
  • @jdm2112 yes. i believe that switch_theme is an event that happens when someone switches a different theme. Oh, that's different. I was looking at the action of the same name, codex.wordpress.org/Plugin_API/Action_Reference/switch_theme. Milo I believe that's what I'm looking for. but why is it passed the stylesheet and not the theme name? – 1.21 gigawatts Nov 7 '15 at 0:24
  • 1
    Although you have already accepted an answer, I have a question. Do you want to permanently switch to another theme for everyone or to switch to another theme on the fly but not permanently and only for current user? – cybmeta Nov 7 '15 at 8:27
  • I have a network site and I want the current user to be able to switch the theme permanently. – 1.21 gigawatts Nov 7 '15 at 8:38

switch_theme() is the function you need but this...

why is someone changing the stylesheet and no longer changing the theme?

... indicates a misunderstanding. You provide the $stylesheet as an argument but you are switching the theme as a whole not just the stylesheet. And, for reasons unknown, $stylesheet isn't the stylesheet. It is:

$stylesheet is the name of your folder slug. It's the same value that you'd use for a child theme, something like twentythirteen.


  • So it sounds like the parameter name is a bit misleading? I'm sure there's probably some history to it or reason. – 1.21 gigawatts Nov 7 '15 at 1:01
  • I don't know what the reasons is, but yes, it is quite misleading. – s_ha_dum Nov 7 '15 at 1:02
  • I'm curious, which action is the more appropiate to run switch_theme(). I think on init but maybe setup_theme? – cybmeta Nov 7 '15 at 8:35
  • @cybmeta sorry. I didn't see this comment. I'm not sure. I'm going to try to run it when a new blog is created. I'll try and find the event. – 1.21 gigawatts Nov 13 '15 at 14:19
  • I'm making a call at the add_action( 'wpmu_new_blog', 'wpse_set_defaults' );. If it's not obvious, I'm running a network site. You will want to find a different action if you are not running the same. Right now, I'm adding an event listener in a plugin page for some reason. I think it should probably be in theme/functions... – 1.21 gigawatts Nov 13 '15 at 14:50

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.