WordPress register script

wp_register_script()

Registers a script file to later connect it using the function wp_enqueue_script (), which saves the sequence of loading scripts.

Registers a script file to later connect it using the function wp_enqueue_script (), which saves the sequence of loading scripts.

When writing a plugin or a theme, it is recommended to connect scripts with this function or its analogue wp_enqueue_script ().

The function must be connected through hooks, because calling a function outside of hooks can create problems:

  • wp_enqueue_scripts, If you want to call a function in the front of the site (front end).
  • admin_enqueue_scripts, To call in the administrative part.
  • login_enqueue_scripts – For the authorization page.


To register a script that already exists in WP, you must first remove it using the wp_deregister_script () function, and then register again with the required parameters.


Calling any of the three script logging functions: wp_deregister_script (), wp_register_script (), or wp_enqueue_script () creates a WP_Scripts class and defines the global variable $ wp_scripts. Before that WordPress knows nothing about this class and does not use it, i.e. No scripts are registered from the table below.

No hooks.

Returns

Version WP 4.3 and better returns true / false. Before that, nothing returned.

About The Author

Leave A Comment?