admin_enqueue_scripts function runs, does not output scripts!
-
I’m developing a theme which includes a widget that allows you to upload & select images using the Media Library.I need to load custom scripts on the widgets admin page in order to do this. In my functions.php file ion the theme root directory, I have the following code:
function widgets_admin_scripts() { wp_enqueue_script('jquery'); wp_enqueue_script('media-upload'); wp_enqueue_script('thickbox'); wp_register_script('media-upload', get_stylesheet_directory() . '/js/media-uploader.js' , array('jquery','media-upload','thickbox')); wp_enqueue_script('media-upload'); wp_enqueue_style('thickbox'); } function load_admin_styles() { wp_enqueue_style('thickbox'); } //add_action( 'admin_print_scripts', 'widgets_admin_scripts' ); //add_action('admin_init', 'widgets_admin_scripts'); //add_action('init', 'widgets_admin_scripts'); //add_action('admin_print_styles', 'load_admin_styles'); //add_action('admin_print_scripts-widgets.php', 'widgets_admin_scripts'); //add_action('admin_print_styles-widgets.php', 'load_admin_styles'); add_action('admin_enqueue_scripts', 'widgets_admin_scripts');
I got this code from a plugin that can be found here.
My problem is that NONE of the wp_enqueue_script calls inside the function are loading ANY scripts in the head. The wp_enqueue_style works perfectly fine.
widgets_admin_scripts()
is definitely being called, but none of thewp_enqueue_script
inside of it are actually outputting scripts. I know its being called because I threw anecho
in there and it appeared on the page.I’m totally baffled – I changed the code in the plugin reflecting the same code that I posted here, and it works perfectly fine as long as its in the plugin.
admin_enqueue_scripts
refuses to enqueue scripts when its called from the functions.php theme file.And it’s not just
admin_enqueue_scripts
;admin_print_scripts
doesn’t work either, noradmin_init
,init
– NONE of them will enqueue & output scripts, all of them will enqueue & output styles with no problem though from functions.php.Tried uninstalling all other plugins, deactivating/reactivating theme, nada. Any ideas, my fellow wordpressers?
- The topic ‘admin_enqueue_scripts function runs, does not output scripts!’ is closed to new replies.