after_switch_theme | WordPress 切换主题后触发 钩子
19
2015-01-05
钩子
do_action( 'after_switch_theme', string $old_name, WP_Theme $old_theme )
描述
如果旧主题仍然存在,则在主题切换后的第一次 WP 加载时触发。
如果旧主题丢失,则参数将是旧主题的 slug。
参数
$old_name
,(字符串) 旧主题名称。
$old_theme
,( WP_Theme ) 旧主题的WP_Theme
实例。
返回值
无
划重点
附加到此钩子的回调函数仅在被激活的主题(和/或子主题)中触发。要在主题停用时执行操作,请使用switch_theme()。
相关函数
来源
文件:wp-includes/theme.php
更新日志
3.3.0
介绍。
示例
为主题添加选项并将它们设置为默认值。
add_action('after_switch_theme', 'mytheme_setup_options'); function mytheme_setup_options () { add_option('mytheme_enable_catalog', 0); add_option('mytheme_enable_features', 0); }
激活主题时更新默认的中等图像大小。
add_action( 'after_switch_theme', 'example_update_default_image_size', 10, 2 ); function example_update_default_image_size( $old_theme_name, $old_theme = false ) { update_option( 'medium_size_w', 800 ); update_option( 'medium_size_h', 400 ); }
本文由 猫斯基 原创发布。
著作权均归用户本人所有。独家文章转载,请联系本站管理员。获得授权后,须注明本文地址! 本文地址:https://www.maosiji.com/2765.html