How to use javascript on backend of wordpress

I want to register a script with wordpress that will work on the backend. I thought any script I registered in my functions.php file would work but it only shows in the front end. Anyone any ideas how to do this?

Related posts

Leave a Reply

2 comments

  1. Try:

    <?php
    
    add_action( 'admin_head', 'myscriptinthe_admin_header' );
    function myscriptinthe_admin_header(){
      echo "<script>alert( 'in the admin head!' )</script>";
    }
    
    add_action( 'admin_head', function(){ ?>    
    <script> alert( 'in the admin head!' ) </script> 
    <?php }); ?>
    
  2. In addition to the answer above, sometimes we may need to add javascript to the footer of WordPress admin backend instead of in the head.

    In this case, we will use the ‘admin_footer‘ hook instead of ‘admin_head‘.