启用WordPress主题或插件后自动跳转到设置页面

当用户启用WordPress主题或插件后,提醒用户进行相关设置,是非常友好的。比较常见的有两种做法:

1.启用后,在后台显示提示语,引导用户进行设置

参考:如何在WordPress后台顶部添加错误提醒信息或升级提醒信息

2.启用后,直接跳转到设置界面,让用户进行设置

下面简单说说第2种做法。

自动跳转到主题设置页面

将下面的代码添加到主题的 functions.php 文件中:

global $pagenow;
if ( is_admin() && isset( $_GET['activated'] ) && $pagenow == 'themes.php' )
{
      wp_redirect( admin_url( '主题设置页面链接' ) );
      exit;
}

自动跳转到插件设置页面

register_activation_hook(__FILE__, 'wpdaxue_plugin_activate');
add_action('admin_init', 'wpdaxue_plugin_redirect');
 
function wpdaxue_plugin_activate() {
    add_option('my_plugin_do_activation_redirect', true);
}
 
function wpdaxue_plugin_redirect() {
    if (get_option('my_plugin_do_activation_redirect', false)) {
        delete_option('my_plugin_do_activation_redirect');
        wp_redirect(admin_url( '插件设置页面链接' ));
    }
}

来源:

https://www.wpdaxue.com/redirect-to-settings-page-after-activation.html

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_32305.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?