The BP Custom file

When you need to set some constants relative to WordPress, you generally use the /wp-config.php file. When you need to include some code to customize to a theme, you generally use the /wp-content/themes/active-theme/functions.php file. When you need to include some code to customize your site, you generally use specific files as must use plugins (eg: /mu-plugins/name-of-your-file.php) or a more convenient way of reaching the same goal is to create a plugin including your custom code as it’s easier to disable if needed (by deactivating the plugin). Of course, you could also use these ways to customize BuddyPress, but we strongly invite you to use a BuddyPress specific way of including advanced configurations or code to customize BuddyPress: the /wp-content/plugins/bp-custom.php file.

The bp-custom.php file The bp-custom.php file

It’s a file you put in your WordPress /wp-content/plugins/ folder to add your custom code, hacks or modifications about BuddyPress.

The bp-custom.php file does not exist by default. If you don’t have a file located at /wp-content/plugins/bp-custom.php, you can create one making sure it begins this way:

<?php
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

Benefits Benefits

  1. The bp-custom.php file runs from the /wp-content/plugins/ folder and is therefore independent from your active theme: this code will always load regardless of what theme you are using.
  2. The bp-custom.php file runs early in the BuddyPress-loading process. This allows you to override various settings in BuddyPress.
  3. The bp-custom.php file is only loaded when BuddyPress is active. This means it’s safer to use this location for you custom BuddyPress code than from the available WordPress ones. In the second case you could use BuddyPress specific functions that aren’t available anymore when BuddyPress is deactivated which could result in a fatal error.