I know similar questions have been answered - I've read some of those answers but, for the life of me, it seems there's something I'm missing/"not getting". So, here goes.
I'm trying to build an admin menu for a WP theme I'm creating from scratch. I've created some sub-pages, and now I want to do a check in enqueue.php so that a stylesheet.css loads ONLY if the user is on one of those pages, and NOT on the whole menu. As far as I understand, I should do a logic check if the page currently displayed is, say, page A, B, or C from MY menu, and have the stylesheet load ONLY if that's true.
Following a YouTube tutorial about theme building, I've reached a stage where my code's this:
function themename_load_admin_scripts( $hook ) {
echo $hook;
if ( ($hook != 'toplevel_page_A') || ($hook != 'toplevel_page_B') ) {
return;
}
wp_register_style( 'themename_admin', get_template_directory_uri() . '/css/themename.admin.css', array(), '1.0.0', 'all');
wp_enqueue_style('themename_admin');
wp_register_script( 'themename-admin-script', get_template_directory_uri() . '/js/themename.admin.js', array('jquery'), '1.0.0', true );
wp_enqueue_script( 'themename-admin-script' );
}
add_action( "admin_enqueue_scripts", 'themename_load_admin_scripts' );
...aaaand it doesn't work. As an extra question, since I want to check multiple pages, not only two, would it be better if I did this check using an array? And if yes... how?
Thanks in advance for any help and suggestions.
Aucun commentaire:
Enregistrer un commentaire