0

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?

1 Answer 1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.