So simple I will explain it step by step:
-
First, use the $hook variable that is WordPress default like this:
function the_themescripts($hook) { echo $hook; } add_action( 'admin_enqueue_scripts', 'dr_theme_options_style_scripts' );
-
Now go to custom page in your admin WP Dashboard and at the top you will see something like
toplevel_page_your_theme_page_slug
if it does not visible to you try to inspect element and see after tag copy that and use like this. -
Use of
$hook
variable. Use it inside the if else loopfunction the_themescripts($hook) { echo $hook; if ($hook == 'toplevel_page_your_page_slug') : // enqueue your script/styles here for your first page endif; if ($hook == 'your second page slug' ) : // enqueue your script/styles here for your first page endif } add_action( 'admin_enqueue_scripts', 'the_themescripts' );
Hope this explanation helps:)