How to add custom javascript to WordPress Admin?
Use the admin_enqueue_scripts
action and the wp_enqueue_script
method to add custom scripts to the admin interface.
This assumes that you have myscript.js
in your plugin folder. Change accordingly. The my_custom_script
handle should be unique for your module and script.
function my_enqueue($hook) { // Only add to the edit.php admin page. // See WP docs. if ('edit.php' !== $hook) { return; } wp_enqueue_script('my_custom_script', plugin_dir_url(__FILE__) . '/myscript.js');}add_action('admin_enqueue_scripts', 'my_enqueue');
There is a snippet for Your functions.php file :
function custom_admin_js() { $url = get_bloginfo('template_directory') . '/js/wp-admin.js'; echo '"<script type="text/javascript" src="'. $url . '"></script>"';}add_action('admin_footer', 'custom_admin_js');
Works fine on Wordpress 3.2.1.
<?phpfunction add_jquery_data() { global $parent_file; if ( isset( $_GET['action'] ) && $_GET['action'] == 'edit' && isset( $_GET['post'] ) && $parent_file == 'edit.php') { // Do some stuff. }}add_filter('admin_head', 'add_jquery_data');?>