Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Using this code from codex:

function my_enqueue($hook) {
if( 'edit.php' != $hook )
    return;
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?

[b]EDIT[/b]:

This is how i have adapted the above code:

function auctionwp_custom_admin_style($hook) {
if( 'edit.php' != $hook )
    return;
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

thanks

share|improve this question
add comment

1 Answer

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
add comment

Your Answer

 
discard

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.