Why are admin scripts not printed

Use the admin_enqueue_scripts hook instead of admin_init

Note: you should use hooks that target admin pages as specifically as possible. e.g.:

  • Plugins: Use the admin_print_scripts-{plugin-page} hook
  • Themes: Use the admin_print_scripts-{theme-page} hook (where {theme-page} is whatever string you use in the add_theme_page() call)
  • Custom Post-Type Edit Page: Use the admin_print_scripts-edit.php hook,

For Custom Post Types, inside your function, do something like the following:

global $typenow;
if( 'portfolio' == $typenow ) {
    // wp_enqueue_script() calls go here
}

(h/t t31os)

Leave a Comment