bbp_enqueue_style

Enqueue a script from the highest priority location in the template stack.

Description

(string) bbp_enqueue_style( (string) $handle = '', (string) $file = '', (array) $dependencies = array(), (constant) $version = false, (string) $media = 'all' ); 

Registers the style if file provided (does NOT overwrite) and enqueues.

Returns (string)

The style filename if one is located.

Parameters (5)

0. $handle — Optional. (string) => ''
Name of the stylesheet.
1. $file — Optional. (string) => ''
Relative path to stylesheet. Example: /css/mystyle.css..
2. $dependencies — Optional. (array) => array()
An array of registered style handles this stylesheet depends on. Default empty array.
3. $version — Optional. (constant) => false
String specifying the stylesheet 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 stylesheet.
4. $media — Optional. (string) => 'all'
The media for which this stylesheet has been defined. Default all.. Accepts all., aural,, braille, handheld, projection, print, screen, tty, or tv.

Usage

  1. if ( !function_exists( 'bbp_enqueue_style' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'bbpress/includes/core/template-functions.php'; 
  3.  
  4. // Name of the stylesheet. 
  5. $handle = ''; 
  6.  
  7. // Relative path to stylesheet. Example: '/css/mystyle.css'. 
  8. $file = ''; 
  9.  
  10. // An array of registered style handles this stylesheet depends on. Default empty array. 
  11. $dependencies = array(); 
  12. $version = false; 
  13. $media = 'all'; 
  14.  
  15. // NOTICE! Understand what this does before running. 
  16. $result = bbp_enqueue_style($handle, $file, $dependencies, $version, $media); 
  17.  

Defined (1)

The function is defined in the following location(s).

/includes/core/template-functions.php  
  1. function bbp_enqueue_style( $handle = '', $file = '', $dependencies = array(), $version = false, $media = 'all' ) { 
  2.  
  3. // No file found yet 
  4. $located = false; 
  5.  
  6. // Trim off any slashes from the template name 
  7. $file = ltrim( $file, '/' ); 
  8.  
  9. // Make sure there is always a version 
  10. if ( empty( $version ) ) { 
  11. $version = bbp_get_version(); 
  12.  
  13. // Loop through template stack 
  14. foreach ( (array) bbp_get_template_stack() as $template_location ) { 
  15.  
  16. // Continue if $template_location is empty 
  17. if ( empty( $template_location ) ) { 
  18. continue; 
  19.  
  20. // Check child theme first 
  21. if ( file_exists( trailingslashit( $template_location ) . $file ) ) { 
  22. $located = trailingslashit( $template_location ) . $file; 
  23. break; 
  24.  
  25. // Enqueue if located 
  26. if ( !empty( $located ) ) { 
  27.  
  28. $content_dir = constant( 'WP_CONTENT_DIR' ); 
  29.  
  30. // IIS (Windows) here 
  31. // Replace back slashes with forward slash 
  32. if ( strpos( $located, '\\' ) !== false ) { 
  33. $located = str_replace( '\\', '/', $located ); 
  34. $content_dir = str_replace( '\\', '/', $content_dir ); 
  35.  
  36. // Make path to file relative to site URL 
  37. $located = str_replace( $content_dir, content_url(), $located ); 
  38.  
  39. // Enqueue the style 
  40. wp_enqueue_style( $handle, $located, $dependencies, $version, $media ); 
  41.  
  42. return $located;