WordPress 主题激活和取消激活钩子

主题激活时动作钩子 after_switch_theme
为了实现一些主题的扩展功能,如创建数据表等操作。可以挂载函数到该钩子上。

do_action( 'after_switch_theme', string $old_name, WP_Theme $old_theme )


如果旧主题仍然存在,则在主题切换后的第一个WP加载上触发。
此操作多次触发,如果旧主题存在或不存在,则参数根据上下文的不同而不同。如果旧主题缺失,参数将是旧主题的片段。

主题取消激活时动作钩子 switch_theme

do_action( 'switch_theme', string $new_name, WP_Theme $new_theme, WP_Theme $old_theme )

使用如下代码,将在取消使用当前主题时执行函数:

function deactivate_my_theme( $new_theme ) {
    //主题取消激活后执行操作
}
add_action( 'switch_theme', 'deactivate_my_theme' );
收藏 0
评论
RESTful API 开发
WP_REST_Response 返回结果类
2021-07-25 23:29:49
WordPress 基础
WordPress 发送邮件
2021-07-26 23:15:49
生成中...
登录
注册
重置密码