WordPress钩子-主题切换后执行-after_switch_theme钩子

WordPress钩子-主题切换后执行-after_switch_theme钩子

简介

after_switch_theme 钩子主要是用来在切换主题时加载你想要实现的功能,并且只会执行一次。

语法

/*其中“function_name”是要调用的函数的名称*/
<?php add_action( 'after_switch_theme', 'function_name' ); ?>

用法

<?php
add_action('after_switch_theme', 'Init_theme');
function Init_theme($oldthemename){
  global $pagenow;
  if ( 'themes.php' == $pagenow && isset( $_GET['activated'] ) ) {
    // options-general.php 改成你的主题设置页面网址
    wp_redirect( admin_url( 'options-general.php' ) );
    exit;
  }
}; 
?>
喜欢就支持以下吧
倾尘SEO
  • 本文由 倾尘SEO 发表于 2021年3月22日
  • 转载请务必保留本文链接:https://www.qcwlseo.com/after_switch_theme.html
 评论   0   访客   0