Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Without using a language file, which file would I go to if I wanted to rename profile tabs? For example, instead of the tab saying "Activity" I want it to say "My Activity". Instead of "Groups" I would make it say "My Groups" etc. Thanks

share|improve this question

1 Answer 1

up vote 1 down vote accepted

Look at the source, you know that already. :)

I didn’t but I bet there is a piece of code looking like this:

_e( 'Activity', 'buddypress' );

… or …

__( 'Activity', 'buddypress' );

Follow the functions, they are wrappers for the function translate() in wp-includes/l10n.php:

/**
 * Retrieves the translation of $text. If there is no translation, or
 * the domain isn't loaded, the original text is returned.
 *
 * @see __() Don't use translate() directly, use __()
 * @since 2.2.0
 * @uses apply_filters() Calls 'gettext' on domain translated text
 *      with the untranslated text as second parameter.
 *
 * @param string $text Text to translate.
 * @param string $domain Domain to retrieve the translated text.
 * @return string Translated text
 */
function translate( $text, $domain = 'default' ) {
    $translations = &get_translations_for_domain( $domain );
    return apply_filters( 'gettext', $translations->translate( $text ), $text, $domain );
}

You see you get a filter: 'gettext' with three arguments (or parameters). Now you can use the filter to change the output.
Add this to your theme’s functions.php or to a plugin:

add_filter( 
    'gettext', // filter name
    'wpse_57673_change_buddypress_profile_tabs', // name of your custom function
    10, // priority
    3 // number of arguments you want to get
);

Now we need the custom function, that’s really simple:

function wpse_57673_change_buddypress_profile_tabs( $translated, $original_text, $domain )
{
    if ( 'buddypress' !== $domain )
    {
        return $translated; // not your text
    }

    // find the text to change
    switch ( $original_text )
    {
        case 'Activity':
            return 'My Activity';

        case 'Groups':
            return 'My Groups';

        default:
            return $translated;
    }
}
share|improve this answer
    
"Look at the source, you know that already. :)" (I felt lazy. I looked in the members template file and couldnt find it and I didn't wanna search anymore) Gosh darnit Toscho, you are brilliant :) + What is this? "wpse_57673" –  Aliyah Jul 7 '12 at 3:04
    
@Aliyah - It is a prefix for making the function name unique, so there's little chance on earth it will conflict with another function declared somewhere (theme or plugin). . . . . . If there are two functions with the same name in your WordPress, the site will break (HTTP Error 500 (Internal Server Error)) due to a Fatal error: Cannot redeclare wpse_57673_change_buddypress_profile_tabs() (previously declared in /path/to/first/function/ocurrence.php) in /path/to/second/function.php. . . . . . It stands for WordPressStackExchange_QuestionIdNumber :) –  brasofilo Jul 7 '12 at 9:12
    
Ah! I completely understand now. That explains why Ive had past issues with "cannot redeclare"! Thanx a million Brasofilo! –  Aliyah Jul 7 '12 at 20:32

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.