Change site template from php

If I understand your question, you should use this inside your foreach:

$argument_to_pass_to_switch_theme = $theme->get_stylesheet();

Just taking a look at the documentation:

The function wp_get_themes()

“…returns an array of WP_Theme objects based on the argument.”

This class WP_Theme has a method get_stylesheet(), which…

“…returns a string with the directory name of the theme’s “stylesheet” files, inside the theme root. If this is a child theme it is the directory from the child theme. “

And the function switch_theme()

“…accepts one argument: $stylesheet of the theme. ($stylesheet is the name of your folder slug.”

Leave a Comment