Support » Plugins » Hacks » admin_print_scripts not loading javascript, but loading stylesheet?

  • Resolved datdesignguy


    Hi Everyone,

    I’m working on a plugin where I need a special javascript and css file loaded on my plugin’s options page. I’ve enqueued these scripts using the admin_print_scripts hook, but only the stylesheet is being loaded, but the javascript is being completely ignored?

    I’m using a PHP Class for my Plugin to prevent name collisions and keep everything nice and neat. And I am also using an instance of the class instead of static methods to keep from having to register a bunch of global variables.

    in my main plugin file, I load the Class IBLikeable, and instantiate it, and attach an action to admin_init and admin_menus as seen here:

    $ibl = new IBLikeable();
    add_action('admin_init', array( $ibl, 'register_settings'));
    add_action('admin_menu', array( $ibl, 'register_admin_menus'));

    Inside my IBLikeable Class, the IBLikeable::register_admin_menus() function looks like this:

    I can’t for the life of me figure out why the wp_enqueue_script call in the IBLikeable::enqueue_admin function isn’t working when the style enqueue above is working just fine.

    Can anybody help me debug?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator bcworkz


    I could deduce how it is done from a class object, but staying on familiar ground, a basic plugin would define a function that calls wp_enqueue_script(). Then that function would be called from the ‘admin_enqueue_scripts’ action.

    function my_load_js(){
    add_action('admin_enqueue_scripts', 'my_load_js');

    I hope this is of some help. You basically just need to use a different action to enqueue your javascript file.

    Hi bcworkz,

    That’s actually what I’ve done in my class. If you look at the pastebin link above, in my plugin class, I’ve a function called enqueue_admin(). This does a simple test to find out if we’re on my plugin’s settings page, and if we are, it registers and enqueues both my stylesheet and my js.

    The stylesheet is being loaded as expected, but not the Javascript. Can’t figure out why. 🙁

    I’d also like to note, that the script is successfully being registered. I inspected the global $wp_scripts variable and found my script’s handle in the $wp_scripts array. But it’s still not being loaded! ARG!

    note to self: Do Not Capitalize the Q in jQuery when referring to its WordPress scripts handle

    In my call to wp_register_script(), I set ‘jQuery’ as a dependency instead of the correct handle ‘jquery’…

    Don’t make my same mistake.


Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘admin_print_scripts not loading javascript, but loading stylesheet?’ is closed to new replies.