bp_get_template_part( string $slug, string|null $name = null, array $args = array() )

Get a BuddyPress template part for display in a theme.


Description Description


Parameters Parameters

$slug

(Required) Template part slug. Used to generate filenames, eg 'friends' for 'friends.php'.

$name

(Optional) Template part name. Used to generate secondary filenames, eg 'personal' for 'activity-personal.php'.

Default value: null

$args

(Optional) Extra args to pass to locate_template().

Default value: array()


Top ↑

Return Return

(false|string) Path to located template. See bp_locate_template().


Top ↑

Source Source

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

function bp_get_template_part( $slug, $name = null ) {

	/**
	 * Fires at the start of bp_get_template_part().
	 *
	 * This is a variable hook that is dependent on the slug passed in.
	 *
	 * @since 1.7.0
	 *
	 * @param string $slug Template part slug requested.
	 * @param string $name Template part name requested.
	 */
	do_action( 'get_template_part_' . $slug, $slug, $name );

	// Setup possible parts.
	$templates = array();
	if ( isset( $name ) ) {
		$templates[] = $slug . '-' . $name . '.php';
	}
	$templates[] = $slug . '.php';

	/**
	 * Filters the template parts to be loaded.
	 *
	 * @since 1.7.0
	 *
	 * @param array  $templates Array of templates located.
	 * @param string $slug      Template part slug requested.
	 * @param string $name      Template part name requested.
	 */
	$templates = apply_filters( 'bp_get_template_part', $templates, $slug, $name );

	// Return the part that is found.
	return bp_locate_template( $templates, true, false );
}

Top ↑

Changelog Changelog

Changelog
Version Description
7.0.0 Added $args parameter.
1.7.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.