Để nhúng file js (javascript, jquery) vào trang quản trị admin của WordPress, chúng ta thêm một action vào admin_enqueue_scripts như sau:
Trong file functions.php ở thêm wordpress, hoặc bất cứ file nào mà code có thể chạy được qua, chúng ta thêm đoạn code sau:
add_action('admin_enqueue_scripts', function (){
wp_enqueue_script('custom_admin_script', plugin_dir_url(__FILE__) . '/js/custom-admin-script.js');
});
Nó sẽ gọi tới file /js/custom-admin-script.js
Trong file này các bạn đặt đoạn code js mà các bạn cần xử lý trong phần admin của WordPress
jQuery(document).ready(function () {
// Process code
console.log('vinasupport.com');
});
Nguồn: vinasupport.com