[wordpress] How to load a custom javascript file at the bottom of the wordpres administration area?

Add the following code to your functions.php file:

function my_enqueue($hook) {
   wp_enqueue_script(
     'my_script', 
     get_stylesheet_directory_uri() . '/assets/js/filename.js',
     array(), 
     false, 
     true
   );
 }
 add_action('admin_enqueue_scripts', 'my_enqueue', 999999); 

Where:
admin_enqueue_scripts enqueues scripts for all admin pages
my_enqueue is the name of the function that will handle the desired funcionality.
999999 specifies the order in which the function associated with the action is executed. With this high value it’s expected that the insertion code will be done near the end of the file.

And inside the function:
'my_script' is the name of the script
get_stylesheet_directory_uri() . '/assets/js/filename.js' is the path of the file
array() no script dependencies
false no script version
true enqueues the script before </body>

Leave a comment

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