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

Get a BuddyPress template part for display in a theme.

Description

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

Return

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

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 BuddyPress 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 BuddyPress 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 );
}

Changelog

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