admin管理员组

文章数量:1391804

I am learning WordPress plugin development. I am trying to attach a jQuery/JavaScript file in Admin Panel. I am using below code in plugins index.php file.

function admin_script() {
        wp_enqueue_script('my_custom_script', plugin_dir_url(__FILE__) . '/myscript.js');
    }

add_action('admin_enqueue_scripts','admin_script');

Is it correct code ? What is my_custom_script here?

I am learning WordPress plugin development. I am trying to attach a jQuery/JavaScript file in Admin Panel. I am using below code in plugins index.php file.

function admin_script() {
        wp_enqueue_script('my_custom_script', plugin_dir_url(__FILE__) . '/myscript.js');
    }

add_action('admin_enqueue_scripts','admin_script');

Is it correct code ? What is my_custom_script here?

Share Improve this question asked Feb 9, 2020 at 10:24 FoysalFoysal 4451 gold badge5 silver badges16 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

Yes, your code is good.

And that my_custom_script is a unique identifier for the script you're enqueueing. You can find the default script handlers/identifiers here — e.g. jquery for the jQuery library that ships with WordPress.

There you can also find more details about the wp_enqueue_script() function, e.g. where should you use the function, the parameters, etc.

本文标签: jqueryAdding JavaScript file in Admin Panel