0

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

1

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.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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