bp_replace_the_content( string $content = '' )

Conditionally replace ‘the_content’.


Replaces the_content() if the post_type being displayed is one that would normally be handled by BuddyPress, but proper single page templates do not exist in the currently active theme.



(string) (Optional) Original post content.

Default value: ''


(string) $content Post content, potentially modified.


File: bp-core/bp-core-theme-compatibility.php

function bp_replace_the_content( $content = '' ) {

	// Bail if not the main loop where theme compat is happening.
	if ( ! bp_do_theme_compat() ) {
		return $content;

	// Set theme compat to false early, to avoid recursion from nested calls to
	// the_content() that execute before theme compat has unhooked itself.
	bp_set_theme_compat_active( false );

	 * Filters the content to replace in the post.
	 * @since BuddyPress 1.7.0
	 * @param string $content Original post content.
	$new_content = apply_filters( 'bp_replace_the_content', $content );

	// Juggle the content around and try to prevent unsightly comments.
	if ( ! empty( $new_content ) && ( $new_content !== $content ) ) {

		// Set the content to be the new content.
		$content = $new_content;

		// Clean up after ourselves.
		unset( $new_content );

		// Reset the $post global.

	// Return possibly hi-jacked content.
	return $content;


Version Description
BuddyPress 1.7.0 Introduced.


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.