如何将主题切换重定向到我的主题选项页面,重定向wp_redirect或wp_safe_redirect的最佳方法是什么:
这里是我的代码:
<?php
function sunset_add_admin_page() {
//Generate Sunset Admin Page
add_menu_page( 'Sunset Theme Options', 'Sunset', 'manage_options', 'alecaddd_sunset', 'sunset_theme_create_page', get_template_directory_uri() . '/img/sunset-icon.png', 110 );
//Generate Sunset Admin Sub Pages
add_submenu_page( 'alecaddd_sunset', 'Sunset Theme Options', 'General', 'manage_options', 'alecaddd_sunset', 'sunset_theme_create_page' );
add_submenu_page( 'alecaddd_sunset', 'Sunset CSS Options', 'Custom CSS', 'manage_options', 'alecaddd_sunset_css', 'sunset_theme_settings_page');
}
add_action( 'admin_menu', 'sunset_add_admin_page' );
function sunset_sidebar_options( )
{
echo "Customize your Sidebar Information";
}
function sunset_theme_create_page() {
}
function sunset_theme_settings_page( )
{
echo "<h1> Hello Submenu </h1>";
}
function my_on_switch_theme($new_theme) {
wp_safe_redirect( $location, $status );
exit;
}
add_action('switch_theme', 'my_on_switch_theme');
答案 0 :(得分:0)
将此代码放在主题functions.php。
中add_action('after_switch_theme', 'mytheme_setup_options');
function mytheme_setup_options () {
wp_safe_redirect($location);
}