bbp_enqueue_script( string $handle = '', string|bool $file = '', $dependencies = array(), $version = false, bool $in_footer = 'all' )
Enqueue a script from the highest priority location in the template stack.
Description
Registers the style if file provided (does NOT overwrite) and enqueues.
Parameters
- $handle
-
(Optional) Name of the script.
Default value: ''
- $file
-
(Optional) Relative path to the script. Example: '/js/myscript.js'.
Default value: ''
- $deps
-
(Required) An array of registered handles this script depends on. Default empty array.
- $ver
-
(Optional) String specifying the script version number, if it has one. This parameter is used to ensure that the correct version is sent to the client regardless of caching, and so should be included if a version number is available and makes sense for the script.
- $in_footer
-
(Optional) Whether to enqueue the script before </head> or before </body>. Default 'false'. Accepts 'false' or 'true'.
Default value: 'all'
Return
(string) The script filename if one is located.
Source
File: bp-forums/core/template-functions.php
function bbp_enqueue_script( $handle = '', $file = '', $dependencies = array(), $version = false, $in_footer = 'all' ) { // No file found yet $located = false; // Trim off any slashes from the template name $file = ltrim( $file, '/' ); // Make sure there is always a version if ( empty( $version ) ) { $version = bbp_get_version(); } // Loop through template stack foreach ( (array) bbp_get_template_stack() as $template_location ) { // Continue if $template_location is empty if ( empty( $template_location ) ) { continue; } // Check child theme first if ( file_exists( trailingslashit( $template_location ) . $file ) ) { $located = trailingslashit( $template_location ) . $file; break; } } // Enqueue if located if ( !empty( $located ) ) { $content_dir = constant( 'WP_CONTENT_DIR' ); // IIS (Windows) here // Replace back slashes with forward slash if ( strpos( $located, '\\' ) !== false ) { $located = str_replace( '\\', '/', $located ); $content_dir = str_replace( '\\', '/', $content_dir ); } // Make path to file relative to site URL $located = str_replace( $content_dir, content_url(), $located ); // Enqueue the style wp_enqueue_script( $handle, $located, $dependencies, $version, $in_footer ); } return $located; }
Changelog
Version | Description |
---|---|
bbPress (r5180) | Introduced. |
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.