WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Using this code from codex:

function my_enqueue($hook) {
if( 'edit.php' != $hook )
wp_enqueue_script( 'my_custom_script', plugins_url('/myscript.js', __FILE__) );
add_action( 'admin_enqueue_scripts', 'my_enqueue' );

this will add a custom stylesheet into wp-admin on the edit page, how can we change this so that we can use a slug from a custom admin options page which has submenus, is there a way we can use the parent menu item slug?


This is how i have adapted the above code:

function auctionwp_custom_admin_style($hook) {
if( 'edit.php' != $hook )
wp_enqueue_style( 'my_custom_script',  get_bloginfo( 'stylesheet_directory' ) .  '/css/custom_style.css', false, '1.0.0' );
add_action( 'admin_enqueue_scripts', 'auctionwp_custom_admin_style' );

what im now trying to do is change the if statement to use parent menu slug rather than edit.php


share|improve this question
up vote 1 down vote accepted

Don't confuse menu structure with page/URL structure. Each one of your pages may have a different hook.

Do this:

function my_enqueue($hook) {
    echo $hook;
add_action( 'admin_enqueue_scripts', 'my_enqueue' );

Load your pages and write down the hook names.

There may be other ways to do this too, like the admin-print-scripts-$hook_suffix hooks. Look in wp-admin/admin-header.php to see what I mean, about line 68.

share|improve this answer
Thanks for that, using your example it has given me the way foreward. – MartinJJ Dec 28 '12 at 1:01

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.