Ignacio Ignacio - 4 months ago 10
Javascript Question

How to add custom javascript to WordPress Admin?

I want to add some custom jquery code to the Edit Post page, something really simple like showing a div when someone presses Publish.

The only restriction is that I want to achieve this through the use of a plugin, not hacking the admin template files.

I've tried echoing some script tags using some actions but it doesn't seem to be the way.

Tim Tim

Use the admin_enqueue_scripts action and the wp_enqueue_script method to add custom scripts to the admin interface:

function my_enqueue( $hook ) {
    if ('edit.php' != $hook) {
    wp_enqueue_script( 'my_custom_script', plugin_dir_url( __FILE__ ) . '/myscript.js' );

add_action('admin_enqueue_scripts', 'my_enqueue');