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.

The title pretty much explains exactly what I'm trying to do. If someone could help me out, that would be awesome. Thanks!

:)

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

the correct way to include files for scripts you can use the hook "admin_print_scripts"

and include your scripts with wp_enqueue_script()

for example:

<?php 
add_action('admin_print_scripts','my_scripts');
function my_scripts(){
   wp_enqueue_script( 'jquery' );
}
?>

and for styles use the hook "admin_print_styles" and include you styles with wp_enqueue_style

for example:

<?php 
add_action('admin_print_styles','my_styles');
function my_styles(){
   wp_enqueue_style( 'myPluginStylesheet', WP_PLUGIN_URL . '/myPlugin/stylesheet.css' );
}
?>

Hope This Helps.

share|improve this answer
add comment

jQuery should already be loaded, it's used throughout the admin area of WordPress.

If you want to include some of your own jQuery, just enqueue the script and set jQuery as a dependancy.

add_action('admin_print_scripts-%HANDLE%','enqueue_my_script');
function enqueue_my_script(){
    // Uncomment line below if using inside a plugin
    //wp_enqueue_script( 'my-script', plugins_url( 'myfile.js', __FILE__ ), array( 'jquery' ) );
    // Uncomment line below if using inside theme functions.php
    //wp_enqueue_script( 'my-script', get_bloginfo( 'stylesheet_directory' ) . '/myfile.js', array( 'jquery' ) );
}

%HANDLE% should be appropriately changed for the handle of your registered page, it's the fifth parameter in add_menu_page and the fourth in add_submenu_page and others such as add_theme_page.

This method will ensure the enqueue is only made for your specific custom page, and not every admin page.

I also covered using registered handles to selectively enqueue in URLs of plugin resources?

Hope that helps..

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.