switch_theme [ WordPress-Funktionen ]
switch_theme ( $stylesheet )
| Parameter: |
|
| Nutzt: | |
| Definiert in: |
|
| Codex |
Switches the theme.
Accepts one argument: $stylesheet of the theme. It also accepts an additional function signature of two arguments: $template then $stylesheet. This is for backwards compatibility.
Quellcode
function switch_theme( $stylesheet ) {
global $wp_theme_directories, $sidebars_widgets;
if ( is_array( $sidebars_widgets ) )
set_theme_mod( 'sidebars_widgets', array( 'time' => time(), 'data' => $sidebars_widgets ) );
$old_theme = wp_get_theme();
$new_theme = wp_get_theme( $stylesheet );
if ( func_num_args() > 1 ) {
$template = $stylesheet;
$stylesheet = func_get_arg( 1 );
} else {
$template = $new_theme->get_template();
}
update_option( 'template', $template );
update_option( 'stylesheet', $stylesheet );
if ( count( $wp_theme_directories ) > 1 ) {
update_option( 'template_root', get_raw_theme_root( $template, true ) );
update_option( 'stylesheet_root', get_raw_theme_root( $stylesheet, true ) );
} else {
delete_option( 'template_root' );
delete_option( 'stylesheet_root' );
}
$new_name = $new_theme->get('Name');
update_option( 'current_theme', $new_name );
if ( is_admin() && false === get_option( 'theme_mods_' . $stylesheet ) ) {
$default_theme_mods = (array) get_option( 'mods_' . $new_name );
add_option( "theme_mods_$stylesheet", $default_theme_mods );
}
update_option( 'theme_switched', $old_theme->get_stylesheet() );
do_action( 'switch_theme', $new_name, $new_theme );
}Beispiele [ wp-snippets.com ]
Top Google Suchergebnisse
- Function Reference/switch theme « WordPress Codex
Description. Switches current theme to new template and stylesheet names. Accepts one argument: $stylesheet of the theme. It also accepts an additional ...
codex.wordpress.org - Plugin API/Action Reference/switch theme « WordPress Codex
Description. switch_theme is triggered when the blog's theme is changed. If used in a theme, it only works if the theme that adds action is the one being disabled.
codex.wordpress.org - Switch_Theme vs. Theme Switching - Shiba Shake
The switch_theme function is exactly what is called when an Administrator changes his WordPress Theme from the Appearance menu. Below is a code fragment ...
shibashake.com - switch_theme (WordPress Function) - WPSeek.com
4 days ago ... Switches the theme. WordPress lookup for switch_theme, a WordPress Function.
wpseek.com
