Reputation: 3775
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?
Upvotes: 2
Views: 1510
Reputation: 22251
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 }); ?>
Upvotes: 2
Reputation: 12867
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'.
Upvotes: 1