I’m working on a plugin that uses thickbox and media-upload to set some images. Neither will load using this code:
function add_my_files() {
echo 'happy happy happy';
wp_register_style( 'adminstyles', plugins_url('/css/slider.css', __FILE__));
wp_enqueue_style( 'adminstyles' );
wp_enqueue_style('thickbox');
wp_enqueue_script('media-upload');
wp_enqueue_script('thickbox');
wp_register_script('hdjs',plugins_url('/js/slider.js', __FILE__),array('media-upload','thickbox'),'',true);
wp_enqueue_script('hdjs');
}
add_action( 'admin_init', 'add_my_files' );
my css and js files load but not thickbox and media-upload.
Thanks
The correct hook to include your asset files in WP is
admin_enqueue_scripts
:NOTE: I recommend you too use
get_current_screen
(seeis_my_admin_screen()
definition below) to just include your js/css files when you actually needed.ref: http://codex.wordpress.org/Plugin_API/Action_Reference/admin_enqueue_scripts
ref: http://codex.wordpress.org/Function_Reference/get_current_screen
Besides hopefully you are using a class to wrap all your plugin or you will have worse problems than this.
Please feedback. I am very interested in this issue because WP plugins puts food and beers on my table.