wp_get_themes()
returns a WP_Theme
object, one of the methods of which, get_stylesheet()
will return the value you need to pass to switch_theme()
You are not likely to get "the variable" to echo
later. If you have more than one theme and is nearly always the case (as you should keep a bundled theme just in case) you are going to have multiple variables, so you need to create an array and not a string.
$themes = wp_get_themes();
foreach ($themes as $theme) {
$argument_to_pass_to_switch_theme[] = $theme->get_stylesheet();
}
var_dump($argument_to_pass_to_switch_theme);
If you run the code as you have it mocked up...
$themes = wp_get_themes();
foreach ($themes as $theme) {
$argument_to_pass_to_switch_theme = $theme->get_stylesheet();
}
var_dump($argument_to_pass_to_switch_theme);
... you will overwrite the $argument_to_pass_to_switch_theme
variable at every iteration of the loop and only end up with the stylesheet name for the last theme in the loop.