do_action_ref_array( 'wp_default_scripts', WP_Scripts $this )

Fires when the WP_Scripts instance is initialized.


Description Description


Parameters Parameters

$this

(WP_Scripts) WP_Scripts instance (passed by reference).


Top ↑

Source Source

File: wp-includes/class.wp-scripts.php

View on Trac


Top ↑

Changelog Changelog

Changelog
Version Description
2.6.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note 1 content
    Contributed by Fleuv

    Add a script where you can refer to from anywhere in your WordPress installation using wp_enqueue_script or admin_enqueue_script.

    First setup the hook, for example in your plugin.

    add_action('wp_default_scripts', function(&$scripts) {
      // Arguments order: `$scripts->add( 'handle', 'url', 'dependencies', 'version', 'in_footer' );`
      // Set "in_footer" argument to 1 to output the script in the footer.
      $scripts->add('my-plugin-script', '/path/to/my-plugin-script.js', array('jquery'), 'alpha', 1);
    });
    

    Now you can use the script from the plugin anywhere for example in your theme.

    add_action('wp_enqueue_scripts', function () {
      wp_enqueue_script('my-theme-script', '/path/to/my-plugin-script.js', array('my-plugin-script'), null, true);
    });
    

    Please make sure that you pick an identical string for the “handle” argument, a good practice is prefixing the handle name with your plugin or theme name.

You must log in before being able to contribute a note or feedback.