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.

I have a plugin that has a top level menu and subsequent submenus. Each one of these pages are going to need their own css and javascript. My code at the moment is:

//main menu
add_menu_page( "My Business", "My Business", "contributor", "fbusiness", array($fmb_admin, "get_page"));
//sub menus
add_submenu_page("fatemagic-business", "Products", "Products", "contributor", "fbusiness-product", array($fmb_product, "get_page"));

What I need is for custom css and scripts for the page that is displayed when the submenu is clicked. I did do this before but have just spent 3hrs trying to find it online and can't. If my memory is correct it looked something like:

$page = add_submenu_page("fatemagic-business", "Products", "Products", "contributor", "fbusiness-product", array($fmb_product, "get_page"));
print_admin_script($page, "http://location/to/javascript");
print_admin_style($page, "http://location/to/css");

Maybe this technique is deprecated? It was about 3 or 4 years ago when I used this technique.

cheers ;)

share|improve this question
    
... found it. arrgggh, sorry for wasting time. Will put up the answer in 5 mins. (knew i'd find it as soon as i asked a question, lol) ans: add_action('admin_print_styles-' . $page, 'func_to_enqueue_script') - will put up detailed answer in about 5 mins –  Coombesy Aug 30 '11 at 9:02
add comment

migrated from stackoverflow.com Aug 30 '11 at 13:15

This question came from our site for professional and enthusiast programmers.

2 Answers

Use the admin_head hook and just echo out what you need to:

function my_admin_head() {
    // Custom Style
    echo '<link rel="stylesheet" href="'.WP_PLUGIN_DIR.'/style.css" type="text/css" />';

    // Our JS
    echo '<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>';

}
add_action('admin_head', 'my_admin_head');
share|improve this answer
    
unfortunately this will add the styles and scripts to all admin pages. But I finally found the answer - literally 2 search's after asking the question lol –  Coombesy Aug 30 '11 at 9:12
add comment
up vote 0 down vote accepted

Sorry for the late reply on this but here is the answer. In order to have custom css for each of my sub-menu admin pages my code needs to be like this:

    //main menu
add_menu_page( "My Business", "My Business", "contributor", "site-business", array($fmb_admin, "get_page"));

//sub menus
$page = add_submenu_page("site-business", "Products", "Products", "contributor", "site-business-product", array($fmb_product, "get_page"));
add_action('admin_print_styles-' . $page, array($fmb_product, "load_styles"));
add_action('admin_print_scripts-' . $page, array($fmb_product, "load_scripts"));

hope this helps someone else ;)

share|improve this answer
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.