I'm trying to load a stylesheet for a particular admin submenu page. The code below is what I came up with after looking up admin_enqueue_scripts
in the codex:
function my_function($hook) {
if ( 'themes.php?page=page-name' != $hook ) {
return;
}
wp_enqueue_style( 'custom-style', get_template_directory_uri() . 'custom-page/style.css' );
}
add_action( 'admin_enqueue_scripts', 'my_function' );
As you can see I'm trying to load it on a submenu page. Not just on 'themes.php', but on a custom page I've created called 'page-name'. The code works if 'themes.php' != $hook
and loads on 'themes.php'. 'themes.php?page=page-name' != $hook
however does not load on 'themes.php?page=page-name'.
Any idea on how to go about this? Thanks in advance!
EDIT: This is how the page is declared
function my_function_settings_page_init() {
$theme_data = wp_get_theme();
$settings_page = add_theme_page( $theme_data->get( 'Name' ). ' About', $theme_data->get( 'Name' ). ' About', 'edit_theme_options', 'page-name', 'my_function_settings_page' );
add_action( "load-{$settings_page}", 'my_function_load_settings_page' );
}
function my_function_load_settings_page() {
$_POST["my-function-settings-submit"] = '';
if ( $_POST["my-function-settings-submit"] == 'Y' ) {
check_admin_referer( "my-function-settings-page" );
my_function_save_theme_settings();
$url_parameters = isset($_GET['tab'])? 'updated=true&tab='.$_GET['tab'] : 'updated=true';
wp_redirect(admin_url('themes.php?page=page-name&'.$url_parameters));
exit;
}
}