bbp_enqueue_style( string $handle = '', string|bool $file = '',  $dependencies = array(),  $version = false, string $media = '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 stylesheet.

Default value: ''

$file

(Optional) Relative path to stylesheet. Example: '/css/mystyle.css'.

Default value: ''

$deps

(Required) An array of registered style handles this stylesheet depends on. Default empty array.

$ver

(Required) 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.

$media

(Optional) The media for which this stylesheet has been defined. Default 'all'. Accepts 'all', 'aural', 'braille', 'handheld', 'projection', 'print', 'screen', 'tty', or 'tv'.

Default value: 'all'

Return

(string) The style filename if one is located.

Source

File: bp-forums/core/template-functions.php

function bbp_enqueue_style( $handle = '', $file = '', $dependencies = array(), $version = false, $media = '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_style( $handle, $located, $dependencies, $version, $media );
	}

	return $located;
}

Changelog

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.