0

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

:)

2 Answers 2

2

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.

1

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..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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