admin_enqueue_scripts
最后更新于:2021-11-25 19:35:01
do_action( ‘admin_enqueue_scripts’, string $hook_suffix )
Enqueue scripts for all admin pages.
参数
- $hook_suffix
-
(string)
The current admin page.
源文件
文件: gc-admin/admin-header.php
function add_script_to_menu_page() { // $pagenow, is a global variable referring to the filename of the current page, // such as ‘admin.php’, ‘post-new.php’ global $pagenow; if ($pagenow != 'nav-menus.php') { return; } // loading css gc_register_style( 'some-css', get_template_directory_uri() . '/css/some.css', false, '1.0.0' ); gc_enqueue_style( 'some-css' ); // loading js gc_register_script( 'some-js', get_template_directory_uri().'/js/some.js', array('jquery-core'), false, true ); gc_enqueue_script( 'some-js' ); } add_action( 'admin_enqueue_scripts', 'add_script_to_menu_page' );
function addPage() { global $customMenu, $customSubMenu; /** * Menu */ $customMenu = add_menu_page( 'Custom Menu', 'Custom Menu', 'manage_options', 'custom-menu', 'customMenuPage', '', 10); /** * Sub Menu Pages */ $customSubMenu = add_submenu_page( 'custom-menu', 'Settings', 'Settings', 'manage_options', 'settings', 'settings_page'); } add_action( 'admin_menu', 'addPage'); /** Enqueue Stylesheets **/ function enqueueAdminStyles( $hook) { global $customMenu, $customSubMenu; $allowed = array( $customMenu, $customSubMenu); if( !in_array( $hook, $allowed) ) { return; } gc_enqueue_style( '-main-', 'assets/admin/css/ucsi.css', '', '1'); } add_action( 'admin_enqueue_scripts', 'enqueueAdminStyles');