String Replacement; or, how to not hack the core.

A common requirement for a BuddyPress site is to change some of the default text around the site. If the text originates in a theme, it is straightforward to create a child theme and make the change directly into the template.

However, if the text that you want to change is within a core php file, or another plugin, the correct approach is to create a language file. Usually used for translations, these language files can also be used to load any text customisation. For full information on both of these, please see the “Customizing Labels, Messages, and URLs” page on the BuddyPress codex.

For plugin developers, sometimes situations come up where you need to change a text string in a theme or plugin and, for whatever reason, you can’t create a child theme, edit a plugin’s core files, or load a custom translation. To solve this problem, I wrote the function below which will insert or update a text string inside the translation table.

This implementation was based on a similar, but different, approach by WordPress core developer Peter Westwood on his blog.

* Replaces a string in the internationalisation table with a custom value.


* @global object $l10n List of domain translated string (gettext_reader) objects

* @param string $find Text to find in the table

* @param string $replace Replacement text


function dpa_bpt_override_i18n( $find, $replace ) {

global $l10n;

if ( isset( $l10n[‘buddypress’] ) && isset( $l10n[‘buddypress’]->entries[$find] ) ) {

$l10n[‘buddypress’]->entries[$find]->translations[0] = $replace;

} else {

$mo = new MO();

$mo->add_entry( array( ‘singular’ => $find, ‘translations’ => array( $replace ) ) );

if ( isset( $l10n[‘buddypress’] ) )

$mo->merge_with( $l10n[‘buddypress’] );

$l10n[‘buddypress’] = $mo;


Tired of having a slow BuddyPress site?

I'm constantly updating my BuddyPress Hosting Guide to help you get the most out of your hosting. SiteGround and WPEngine have proven to be fast and reliable but see my BuddyPress Hosting guide for a full overview of your options


40% Discount on the first year of BuddyPress hosting on WPEngine!

Currently WP Engine is running a promotion where they give 40% discount for the first year of hosting on any of their plans. Use code SSL40OFF on Personal, Professional, or Business plans on WP

About Bowe Frankema

Building communities on BuddyPress is something I am very passionate about. The decision to focus exclusively on BuddyPress projects over the last few years inspired me to share back some of the things I've learned here on BP-Tricks! You can find me on WordCamps & BuddyCamps across the globe and on Twitter! Follow me on Twitter


One response to “String Replacement; or, how to not hack the core.

  1. I still have the issue of my slug for the group forum not changing.

    I have managed to change its display but not its slug.

    The define( ‘BP_FORUMS_SLUG’, ‘forums’ ); is for the main forums group. I want to change the product forum slug.

    Any ideas?


Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">