wp_print_scripts

The timeline below displays how wordpress function wp_print_scripts has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.4

/**
 * Prints scripts in document head that are in the $handles queue.
 *
 * Called by admin-header.php and {@see 'wp_head'} hook. Since it is called by wp_head on every page load,
 * the function does not instantiate the WP_Scripts object unless script names are explicitly passed.
 * Makes use of already-instantiated `$wp_scripts` global if present. Use provided {@see 'wp_print_scripts'}
 * hook to register/enqueue new scripts.
 *
 * @see WP_Scripts::do_item()
 * @global WP_Scripts $wp_scripts The WP_Scripts object for printing scripts.
 *
 * @since 2.1.0
 *
 * @param string|string[]|false $handles Optional. Scripts to be printed. Default 'false'.
 * @return string[] On success, an array of handles of processed WP_Dependencies items; otherwise, an empty array.
 */
function wp_print_scripts($handles = false)
{
    global $wp_scripts;
    /**
     * Fires before scripts in the $handles queue are printed.
     *
     * @since 2.1.0
     */
    do_action('wp_print_scripts');
    if ('' === $handles) {
        // For 'wp_head'.
        $handles = false;
    }
    _wp_scripts_maybe_doing_it_wrong(__FUNCTION__);
    if (!$wp_scripts instanceof WP_Scripts) {
        if (!$handles) {
            return array();
            // No need to instantiate if nothing is there.
        }
    }
    return wp_scripts()->do_items($handles);
}

WordPress Version: 6.3

/**
 * Prints scripts in document head that are in the $handles queue.
 *
 * Called by admin-header.php and {@see 'wp_head'} hook. Since it is called by wp_head on every page load,
 * the function does not instantiate the WP_Scripts object unless script names are explicitly passed.
 * Makes use of already-instantiated $wp_scripts global if present. Use provided {@see 'wp_print_scripts'}
 * hook to register/enqueue new scripts.
 *
 * @see WP_Scripts::do_item()
 * @global WP_Scripts $wp_scripts The WP_Scripts object for printing scripts.
 *
 * @since 2.1.0
 *
 * @param string|string[]|false $handles Optional. Scripts to be printed. Default 'false'.
 * @return string[] On success, an array of handles of processed WP_Dependencies items; otherwise, an empty array.
 */
function wp_print_scripts($handles = false)
{
    global $wp_scripts;
    /**
     * Fires before scripts in the $handles queue are printed.
     *
     * @since 2.1.0
     */
    do_action('wp_print_scripts');
    if ('' === $handles) {
        // For 'wp_head'.
        $handles = false;
    }
    _wp_scripts_maybe_doing_it_wrong(__FUNCTION__);
    if (!$wp_scripts instanceof WP_Scripts) {
        if (!$handles) {
            return array();
            // No need to instantiate if nothing is there.
        }
    }
    return wp_scripts()->do_items($handles);
}

WordPress Version: 5.5

/**
 * Prints scripts in document head that are in the $handles queue.
 *
 * Called by admin-header.php and {@see 'wp_head'} hook. Since it is called by wp_head on every page load,
 * the function does not instantiate the WP_Scripts object unless script names are explicitly passed.
 * Makes use of already-instantiated $wp_scripts global if present. Use provided {@see 'wp_print_scripts'}
 * hook to register/enqueue new scripts.
 *
 * @see WP_Scripts::do_item()
 * @global WP_Scripts $wp_scripts The WP_Scripts object for printing scripts.
 *
 * @since 2.1.0
 *
 * @param string|bool|array $handles Optional. Scripts to be printed. Default 'false'.
 * @return string[] On success, an array of handles of processed WP_Dependencies items; otherwise, an empty array.
 */
function wp_print_scripts($handles = false)
{
    global $wp_scripts;
    /**
     * Fires before scripts in the $handles queue are printed.
     *
     * @since 2.1.0
     */
    do_action('wp_print_scripts');
    if ('' === $handles) {
        // For 'wp_head'.
        $handles = false;
    }
    _wp_scripts_maybe_doing_it_wrong(__FUNCTION__);
    if (!$wp_scripts instanceof WP_Scripts) {
        if (!$handles) {
            return array();
            // No need to instantiate if nothing is there.
        }
    }
    return wp_scripts()->do_items($handles);
}

WordPress Version: 5.4

/**
 * Prints scripts in document head that are in the $handles queue.
 *
 * Called by admin-header.php and {@see 'wp_head'} hook. Since it is called by wp_head on every page load,
 * the function does not instantiate the WP_Scripts object unless script names are explicitly passed.
 * Makes use of already-instantiated $wp_scripts global if present. Use provided {@see 'wp_print_scripts'}
 * hook to register/enqueue new scripts.
 *
 * @see WP_Scripts::do_item()
 * @global WP_Scripts $wp_scripts The WP_Scripts object for printing scripts.
 *
 * @since 2.1.0
 *
 * @param string|bool|array $handles Optional. Scripts to be printed. Default 'false'.
 * @return string[] On success, an array of handles of processed WP_Dependencies items; otherwise, an empty array.
 */
function wp_print_scripts($handles = false)
{
    /**
     * Fires before scripts in the $handles queue are printed.
     *
     * @since 2.1.0
     */
    do_action('wp_print_scripts');
    if ('' === $handles) {
        // For 'wp_head'.
        $handles = false;
    }
    _wp_scripts_maybe_doing_it_wrong(__FUNCTION__);
    global $wp_scripts;
    if (!$wp_scripts instanceof WP_Scripts) {
        if (!$handles) {
            return array();
            // No need to instantiate if nothing is there.
        }
    }
    return wp_scripts()->do_items($handles);
}

WordPress Version: 5.3

/**
 * Prints scripts in document head that are in the $handles queue.
 *
 * Called by admin-header.php and {@see 'wp_head'} hook. Since it is called by wp_head on every page load,
 * the function does not instantiate the WP_Scripts object unless script names are explicitly passed.
 * Makes use of already-instantiated $wp_scripts global if present. Use provided {@see 'wp_print_scripts'}
 * hook to register/enqueue new scripts.
 *
 * @see WP_Scripts::do_item()
 * @global WP_Scripts $wp_scripts The WP_Scripts object for printing scripts.
 *
 * @since 2.1.0
 *
 * @param string|bool|array $handles Optional. Scripts to be printed. Default 'false'.
 * @return array On success, a processed array of WP_Dependencies items; otherwise, an empty array.
 */
function wp_print_scripts($handles = false)
{
    /**
     * Fires before scripts in the $handles queue are printed.
     *
     * @since 2.1.0
     */
    do_action('wp_print_scripts');
    if ('' === $handles) {
        // for wp_head
        $handles = false;
    }
    _wp_scripts_maybe_doing_it_wrong(__FUNCTION__);
    global $wp_scripts;
    if (!$wp_scripts instanceof WP_Scripts) {
        if (!$handles) {
            return array();
            // No need to instantiate if nothing is there.
        }
    }
    return wp_scripts()->do_items($handles);
}

WordPress Version: 4.6

/**
 * Prints scripts in document head that are in the $handles queue.
 *
 * Called by admin-header.php and {@see 'wp_head'} hook. Since it is called by wp_head on every page load,
 * the function does not instantiate the WP_Scripts object unless script names are explicitly passed.
 * Makes use of already-instantiated $wp_scripts global if present. Use provided {@see 'wp_print_scripts'}
 * hook to register/enqueue new scripts.
 *
 * @see WP_Scripts::do_items()
 * @global WP_Scripts $wp_scripts The WP_Scripts object for printing scripts.
 *
 * @since 2.1.0
 *
 * @param string|bool|array $handles Optional. Scripts to be printed. Default 'false'.
 * @return array On success, a processed array of WP_Dependencies items; otherwise, an empty array.
 */
function wp_print_scripts($handles = false)
{
    /**
     * Fires before scripts in the $handles queue are printed.
     *
     * @since 2.1.0
     */
    do_action('wp_print_scripts');
    if ('' === $handles) {
        // for wp_head
        $handles = false;
    }
    _wp_scripts_maybe_doing_it_wrong(__FUNCTION__);
    global $wp_scripts;
    if (!$wp_scripts instanceof WP_Scripts) {
        if (!$handles) {
            return array();
            // No need to instantiate if nothing is there.
        }
    }
    return wp_scripts()->do_items($handles);
}

WordPress Version: 4.5

/**
 * Print scripts in document head that are in the $handles queue.
 *
 * Called by admin-header.php and wp_head hook. Since it is called by wp_head on every page load,
 * the function does not instantiate the WP_Scripts object unless script names are explicitly passed.
 * Makes use of already-instantiated $wp_scripts global if present. Use provided wp_print_scripts
 * hook to register/enqueue new scripts.
 *
 * @see WP_Scripts::do_items()
 * @global WP_Scripts $wp_scripts The WP_Scripts object for printing scripts.
 *
 * @since 2.1.0
 *
 * @param string|bool|array $handles Optional. Scripts to be printed. Default 'false'.
 * @return array On success, a processed array of WP_Dependencies items; otherwise, an empty array.
 */
function wp_print_scripts($handles = false)
{
    /**
     * Fires before scripts in the $handles queue are printed.
     *
     * @since 2.1.0
     */
    do_action('wp_print_scripts');
    if ('' === $handles) {
        // for wp_head
        $handles = false;
    }
    _wp_scripts_maybe_doing_it_wrong(__FUNCTION__);
    global $wp_scripts;
    if (!$wp_scripts instanceof WP_Scripts) {
        if (!$handles) {
            return array();
            // No need to instantiate if nothing is there.
        }
    }
    return wp_scripts()->do_items($handles);
}

WordPress Version: 4.2

/**
 * Print scripts in document head that are in the $handles queue.
 *
 * Called by admin-header.php and wp_head hook. Since it is called by wp_head on every page load,
 * the function does not instantiate the WP_Scripts object unless script names are explicitly passed.
 * Makes use of already-instantiated $wp_scripts global if present. Use provided wp_print_scripts
 * hook to register/enqueue new scripts.
 *
 * @see WP_Scripts::do_items()
 * @global WP_Scripts $wp_scripts The WP_Scripts object for printing scripts.
 *
 * @since 2.6.0
 *
 * @param string|bool|array $handles Optional. Scripts to be printed. Default 'false'.
 * @return array On success, a processed array of WP_Dependencies items; otherwise, an empty array.
 */
function wp_print_scripts($handles = false)
{
    /**
     * Fires before scripts in the $handles queue are printed.
     *
     * @since 2.1.0
     */
    do_action('wp_print_scripts');
    if ('' === $handles) {
        // for wp_head
        $handles = false;
    }
    _wp_scripts_maybe_doing_it_wrong(__FUNCTION__);
    global $wp_scripts;
    if (!$wp_scripts instanceof WP_Scripts) {
        if (!$handles) {
            return array();
            // No need to instantiate if nothing is there.
        }
    }
    return wp_scripts()->do_items($handles);
}

WordPress Version: 4.1

/**
 * BackPress Scripts Procedural API
 *
 * @since 2.6.0
 *
 * @package WordPress
 * @subpackage BackPress
 */
/**
 * Print scripts in document head that are in the $handles queue.
 *
 * Called by admin-header.php and wp_head hook. Since it is called by wp_head on every page load,
 * the function does not instantiate the WP_Scripts object unless script names are explicitly passed.
 * Makes use of already-instantiated $wp_scripts global if present. Use provided wp_print_scripts
 * hook to register/enqueue new scripts.
 *
 * @see WP_Scripts::do_items()
 * @global WP_Scripts $wp_scripts The WP_Scripts object for printing scripts.
 *
 * @since 2.6.0
 *
 * @param string|bool|array $handles Optional. Scripts to be printed. Default 'false'.
 * @return array On success, a processed array of WP_Dependencies items; otherwise, an empty array.
 */
function wp_print_scripts($handles = false)
{
    /**
     * Fires before scripts in the $handles queue are printed.
     *
     * @since 2.1.0
     */
    do_action('wp_print_scripts');
    if ('' === $handles) {
        // for wp_head
        $handles = false;
    }
    global $wp_scripts;
    if (!is_a($wp_scripts, 'WP_Scripts')) {
        if (!did_action('init')) {
            _doing_it_wrong(__FUNCTION__, sprintf(__('Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.'), '<code>wp_enqueue_scripts</code>', '<code>admin_enqueue_scripts</code>', '<code>login_enqueue_scripts</code>'), '3.3');
        }
        if (!$handles) {
            return array();
        } else {
            $wp_scripts = new WP_Scripts();
        }
    }
    return $wp_scripts->do_items($handles);
}

WordPress Version: 3.8

/**
 * BackPress Scripts Procedural API
 *
 * @since 2.6.0
 *
 * @package WordPress
 * @subpackage BackPress
 */
/**
 * Print scripts in document head that are in the $handles queue.
 *
 * Called by admin-header.php and wp_head hook. Since it is called by wp_head on every page load,
 * the function does not instantiate the WP_Scripts object unless script names are explicitly passed.
 * Makes use of already-instantiated $wp_scripts global if present. Use provided wp_print_scripts
 * hook to register/enqueue new scripts.
 *
 * @see WP_Scripts::do_items()
 * @global WP_Scripts $wp_scripts The WP_Scripts object for printing scripts.
 *
 * @since 2.6.0
 *
 * @param array|bool $handles Optional. Scripts to be printed. Default 'false'.
 * @return array On success, a processed array of WP_Dependencies items; otherwise, an empty array.
 */
function wp_print_scripts($handles = false)
{
    /**
     * Fires before scripts in the $handles queue are printed.
     *
     * @since 2.1.0
     */
    do_action('wp_print_scripts');
    if ('' === $handles) {
        // for wp_head
        $handles = false;
    }
    global $wp_scripts;
    if (!is_a($wp_scripts, 'WP_Scripts')) {
        if (!did_action('init')) {
            _doing_it_wrong(__FUNCTION__, sprintf(__('Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.'), '<code>wp_enqueue_scripts</code>', '<code>admin_enqueue_scripts</code>', '<code>login_enqueue_scripts</code>'), '3.3');
        }
        if (!$handles) {
            return array();
        } else {
            $wp_scripts = new WP_Scripts();
        }
    }
    return $wp_scripts->do_items($handles);
}

WordPress Version: 3.7

/**
 * BackPress Scripts Procedural API
 *
 * @since 2.6.0
 *
 * @package WordPress
 * @subpackage BackPress
 */
/**
 * Print scripts in document head that are in the $handles queue.
 *
 * Called by admin-header.php and wp_head hook. Since it is called by wp_head on every page load,
 * the function does not instantiate the WP_Scripts object unless script names are explicitly passed.
 * Makes use of already-instantiated $wp_scripts global if present. Use provided wp_print_scripts
 * hook to register/enqueue new scripts.
 *
 * @see WP_Scripts::do_items()
 * @global WP_Scripts $wp_scripts The WP_Scripts object for printing scripts.
 *
 * @since 2.6.0
 *
 * @param array|bool $handles Optional. Scripts to be printed. Default 'false'.
 * @return array On success, a processed array of WP_Dependencies items; otherwise, an empty array.
 */
function wp_print_scripts($handles = false)
{
    do_action('wp_print_scripts');
    if ('' === $handles) {
        // for wp_head
        $handles = false;
    }
    global $wp_scripts;
    if (!is_a($wp_scripts, 'WP_Scripts')) {
        if (!did_action('init')) {
            _doing_it_wrong(__FUNCTION__, sprintf(__('Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.'), '<code>wp_enqueue_scripts</code>', '<code>admin_enqueue_scripts</code>', '<code>login_enqueue_scripts</code>'), '3.3');
        }
        if (!$handles) {
            return array();
        } else {
            $wp_scripts = new WP_Scripts();
        }
    }
    return $wp_scripts->do_items($handles);
}