WordPress add JavaScript to admin

Filed Under: WordPress by Miloš Spasić Written on February 26th, 2016

WordPress add JavaScript to admin

Here is how to add custom JavaScript to WordPress admin area (dashboard):

Just copy code below and paste it to your themes functions.php file.

Dont forget to change "your-theme/assets/js/CustomJS.js" with path to your JS file.

// Add Custom JS to WordPress Admin Area Footer
function custom_admin_js() {
   echo '<script type="text/javascript" src="' . esc_url( home_url( '/' ) ) . 'wp-content/themes/your-theme/assets/js/CustomJS.js"></script>';
}
add_action('admin_footer', 'custom_admin_js');
// Add Custom JS to WordPress Admin Area Header
function custom_admin_js() {
    echo '<script type="text/javascript" src="' . esc_url( home_url( '/' ) ) . 'wp-content/themes/your-theme/assets/js/CustomJS.js"></script>';
}
add_action('admin_head', 'custom_admin_js');

Top of Page

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Top of Page