我有一个插件,它有一个顶级菜单和后续子菜单。这些页面中的每一个都需要自己的css和javascript。我目前的代码是:
//main menu
add_menu_page( "My Business", "My Business", "contributor", "fbusiness", array($fmb_admin, "get_page"));
//sub menus
add_submenu_page("fatemagic-business", "Products", "Products", "contributor", "fbusiness-product", array($fmb_product, "get_page"));
我需要的是为单击子菜单时显示的页面定制css和脚本。我以前确实这样做过,但刚刚花了3小时的时间试图在网上找到它,但却找不到。如果我的记忆正确,它看起来像:
$page = add_submenu_page("fatemagic-business", "Products", "Products", "contributor", "fbusiness-product", array($fmb_product, "get_page"));
print_admin_script($page, "http://location/to/javascript");
print_admin_style($page, "http://location/to/css");
也许这种技术已经被弃用了?大约是3、4年前我使用这项技术的时候。
干杯;)
最合适的回答,由SO网友:Daithí 整理而成
很抱歉延迟回复,但这里是答案。为了为我的每个子菜单管理页面提供自定义css,我的代码需要如下所示:
//main menu
add_menu_page( "My Business", "My Business", "contributor", "site-business", array($fmb_admin, "get_page"));
//sub menus
$page = add_submenu_page("site-business", "Products", "Products", "contributor", "site-business-product", array($fmb_product, "get_page"));
add_action(\'admin_print_styles-\' . $page, array($fmb_product, "load_styles"));
add_action(\'admin_print_scripts-\' . $page, array($fmb_product, "load_scripts"));
希望这对其他人有帮助;)