bp_locate_template_asset( string $filename )

Get file data of the highest priority asset that exists.

Description

Similar to bp_locate_template(), but for files like CSS and JS.

Parameters

$filename

(Required) Relative filename to search for.

Return

(false|array) Array of asset data if one is located (includes absolute filepath and URI). Boolean false on failure.

Source

File: bp-core/bp-core-template-loader.php

function bp_locate_template_asset( $filename ) {
	// Ensure assets can be located when running from /src/.
	if ( defined( 'BP_SOURCE_SUBDIRECTORY' ) && 'src' === BP_SOURCE_SUBDIRECTORY ) {
		$filename = str_replace( '.min', '', $filename );
	}

	// Use bp_locate_template() to find our asset.
	$located = bp_locate_template( $filename, false );
	if ( false === $located ) {
		return false;
	}

	// Set up data array.
	$data = array();
	$data['file'] = $data['uri'] = $located;

	$find = array(
		get_theme_root(),
		bp_get_theme_compat_dir()
	);

	$replace = array(
		get_theme_root_uri(),
		bp_get_theme_compat_url()
	);

	// Make sure URI path is relative to site URL.
	$data['uri'] = str_replace( $find, $replace, $data['uri'] );

	return $data;
}

Changelog

Changelog
Version Description
BuddyPress 2.6.0 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.