你可以退房this 尤金·曼努伊洛夫的回答很好。在您的情况下,相关的管理页面操作是:
load-appearance_page_customstyle
以及要编辑的自定义样式表的url:
get_admin_url().\'theme-editor.php?file=custom-stylesheet.css&theme=\'. get_stylesheet().\'&scrollto=0\';
那么您的代码示例将是:
add_action(\'admin_menu\', \'add_appearance_menu\');
function add_appearance_menu() {
add_submenu_page( \'themes.php\', \'Custom Stylesheet\', \'customstyle\', \'manage_options\', \'customstyle\', \'__return_null\');
}
add_action( \'load-appearance_page_customstyle\', \'custom_redirect\' );
function custom_redirect() {
if ( \'customstyle\' === filter_input( INPUT_GET, \'page\' ) ) {
$file2edit = "custom-stylesheet.css"; // change this to your needs
$location = get_admin_url().\'theme-editor.php?file=\'.$file2edit.\'&theme=\'. get_stylesheet().\'&scrollto=0\';
wp_redirect( $location, 301);
exit();
}
}
单击子菜单链接时
http://example.com/wp-admin/themes.php?page=customstyle
钩子load-appearance_page_customstyle
从…起
do_action(\'load-\' . $page_hook);
在中
/wp-admin/admin.php
使用上面定义的重定向激活。