Skip to:
Content
Pages
Categories
Search
Top
Bottom

Change meta/page title for user pages


  • project_subdomain
    Participant

    @project_subdomain

    Hi!
    I ‘d like to change the meta titles (browser’s page title) for bbpress’ profile/user pages as it was not catched by the translation in my language.
    So far I tried this which does not work:

    function amend_title () 
    
    { elseif ( bbp_is_single_user() ) { 
    
    	if ( bbp_is_user_home() ) { 
    
    $new_title['text'] = esc_attr_x( 'Translation of Your Profile', 'User viewing his/her own profile', 'bbpress' ); 
    } 
    } else { 
    			$new_title['text'] = sprintf( esc_attr_x( "%s's", 'User viewing another users profile', 'bbpress' ), get_userdata( bbp_get_user_id() )->display_name ); 
    		} 
    
    if ( bbp_is_single_user_topics() ) { 
    			$new_title['format'] = esc_attr__( "%s Translation of topics",        'bbpress' ); 
    
    } elseif ( bbp_is_single_user_replies() ) { 
    			$new_title['format'] = esc_attr__( "%s Translation of replies",       'bbpress' ); 
    
    } elseif ( bbp_is_favorites() ) { 
    			$new_title['format'] = esc_attr__( "%s Translation of favorites",     'bbpress' ); 
    
    } elseif ( bbp_is_subscriptions() ) { 
    			$new_title['format'] = esc_attr__( "%s Translation of subscriptions", 'bbpress' ); 
    } else { 
    			$new_title['format'] = esc_attr__( "%s Translation of profile",       'bbpress' ); 
    		} 
    } elseif ( bbp_is_single_user_edit() ) { 
    if ( bbp_is_user_home_edit() ) { 
    			$new_title['text']   = esc_attr__( 'Translation of edit profile', 'bbpress' ); 
    } else { 
    			$new_title['text']   = get_userdata( bbp_get_user_id() )->display_name; 
    			$new_title['format'] = esc_attr__( "Translation of edit %s's profile", 'bbpress' ); 
    		} 
    
     return $new_title; 
    } 
    add_filter('bbp_before_title_parse_args', 'amend_title' ); 

    Any help is much appreciated!
    Thanks!

Viewing 22 replies - 1 through 22 (of 22 total)

  • project_subdomain
    Participant

    @project_subdomain

    ok, the code above could not work.

    the remaining issue comes from a different singular/plural form of “Your” in my language.

    came across this, but I’m not sure what’s been the specific purpose of that changeset:
    trac 5105


    project_subdomain
    Participant

    @project_subdomain

    still struggling with this.
    would be great to know the purpose of those changes.


    Robkk
    Moderator

    @robkk

    What language is the translation file you are using??


    project_subdomain
    Participant

    @project_subdomain

    de (german)


    Robkk
    Moderator

    @robkk

    ok will test it out/ see if I can translate it.


    pankalkulator
    Participant

    @pankalkulator

    Have the same issue. Will test it as well.


    Robkk
    Moderator

    @robkk

    @project_subdomain

    I tried the German translation and it seems to translate the titles for the profile pages well, I tested it without an SEO plugin activated though.


    project_subdomain
    Participant

    @project_subdomain

    thanks, robkk. that’s weird as I don’t have SEO plugins activated as well.
    This is what’s in my template.php:

    /** Users *****************************************************************/
    
    	// Profile page
    	} elseif ( bbp_is_single_user() ) {
    
    		// User is viewing their own profile
    		if ( bbp_is_user_home() ) {
    			$new_title['text'] = esc_attr_x( 'Your', 'User viewing his/her own profile', 'bbpress' );
    
    		// User is viewing someone else's profile (so use their display name)
    		} else {
    			$new_title['text'] = sprintf( esc_attr_x( "%s's", 'User viewing another users profile', 'bbpress' ), get_userdata( bbp_get_user_id() )->display_name );
    		}
    
    		// User topics created
    		if ( bbp_is_single_user_topics() ) {
    			$new_title['format'] = esc_attr__( "%s Topics",        'bbpress' );
    
    		// User rueplies created
    		} elseif ( bbp_is_single_user_replies() ) {
    			$new_title['format'] = esc_attr__( "%s Replies",       'bbpress' );
    
    		// User favorites
    		} elseif ( bbp_is_favorites() ) {
    			$new_title['format'] = esc_attr__( "%s Favorites",     'bbpress' );
    
    		// User subscriptions
    		} elseif ( bbp_is_subscriptions() ) {
    			$new_title['format'] = esc_attr__( "%s Subscriptions", 'bbpress' );
    
    		// User "home"
    		} else {
    			$new_title['format'] = esc_attr__( "%s Profile",       'bbpress' );
    		}

    Robkk
    Moderator

    @robkk

    which template.php file?? Did that fix your issue?? You probably shouldn’t be editing core files if that is what it is.


    project_subdomain
    Participant

    @project_subdomain

    this is a part of the original bbpress/inc/common/template.php (which i thought is relevant on this). untouched. just looked at it for finding a possible reason for the behaviour. i still don’t get it to work.


    Robkk
    Moderator

    @robkk

    You are using the latest German language file right??


    project_subdomain
    Participant

    @project_subdomain

    Just made a new updated installation of bbpress, just in case..with latest german language file.
    now the prefix is “I” in German on all profile pages. Should be:
    My (singular, German: “Mein”) Profile
    My (plural, German: “Meine”) posts, replies, subscriptions, favorites,..


    Robkk
    Moderator

    @robkk

    Funny thing is that bbPress has listed at least 6 German languages, maybe the one you would want needs to be the German → German (Formal)??

    German
    Swiss German
    German (Switzerland)
    German → German (Formal)
    Swiss German → Swiss German (Formal)
    German (Switzerland) → German (Switzerland) Informal

    project_subdomain
    Participant

    @project_subdomain

    It’s default German (informal) what I’m looking for. Should be the same for formal as well though. Could you provide a link to those so that I can try any of these again?


    Robkk
    Moderator

    @robkk

    All of what is listed is here, only the German language you are using is the 100% finished translation.

    https://translate.wordpress.org/projects/wp-plugins/bbpress/stable

    Shouldn’t it be Dein Profil for a straight translation of Your Profile which is what bbPress has for profiles??

    For custom plugin translations I have to look into it, there use to be a way to have custom plugin translations.

    This old code is what I think you could use and test. Edit the existing German language files with something like Poedit. Save them. And Place them in a child theme for example, and put the url in the code below.

    function load_bbpress_tr_mofile( $mofile, $domain )
    {
        if ( 'bbpress' == $domain )
        {
            // replace this. :)
            return 'FULL_PATH_TO_YOUR_FILE';
        }
        return $mofile;
    }
    add_filter( 'load_textdomain_mofile', 'load_bbpress_tr_mofile', 10, 2 );

    project_subdomain
    Participant

    @project_subdomain

    Thanks, Robkk. Changing “Your” to whatever is no problem. It’s just that the German language needs a singular translation of “Your” for the user’s home page and a plural translation of “Your” for all other user pages like subscriptions etc.
    It’s the same string of “Your” that’s used for Profile as well as for Topics, Replies, Subscriptions, Favorites.


    Robkk
    Moderator

    @robkk

    I think this will do it. Edit any words in English to German.

    function my_german_titles( $new_title ){
    // Profile page
    	if ( bbp_is_single_user() ) {
    
    		// User is viewing their own profile
    		if ( bbp_is_user_home() ) {
    			$new_title['text'] = esc_attr_x( 'Mien', 'User viewing his/her own profile', 'bbpress' );
    			
    
    		// User is viewing someone else's profile (so use their display name)
    		} else {
    			$new_title['text'] = sprintf( esc_attr_x( "%s's", 'User viewing another users profile', 'bbpress' ), get_userdata( bbp_get_user_id() )->display_name );
    		}
    
    		// User topics created
    		if ( bbp_is_user_home() && bbp_is_single_user_topics() ) {
    			$new_title['format'] = esc_attr__( "Miene Topics",        'bbpress' );
    
    		// User rueplies created
    		} elseif ( bbp_is_user_home() && bbp_is_single_user_replies() ) {
    			$new_title['format'] = esc_attr__( "Miene Replies",       'bbpress' );
    
    		// User favorites
    		} elseif ( bbp_is_user_home() && bbp_is_favorites() ) {
    			$new_title['format'] = esc_attr__( "Miene Favorites",     'bbpress' );
    
    		// User subscriptions
    		} elseif ( bbp_is_user_home() && bbp_is_subscriptions() ) {
    			$new_title['format'] = esc_attr__( "Miene Subscriptions", 'bbpress' );
    		}
    
    	// Profile edit page
    	} elseif ( bbp_is_single_user_edit() ) {
    
    		// Current user
    		if ( bbp_is_user_home_edit() ) {
    			$new_title['text']   = esc_attr__( 'Edit Your Profile', 'bbpress' );
    
    		// Other user
    		} else {
    			$new_title['text']   = get_userdata( bbp_get_user_id() )->display_name;
    			$new_title['format'] = esc_attr__( "Edit %s's Profile", 'bbpress' );
    		}
        
    }
        
        return $new_title;
    }    
    
    add_filter( 'bbp_before_title_parse_args', 'my_german_titles' );

    project_subdomain
    Participant

    @project_subdomain

    thanks, Robkk, this works!


    project_subdomain
    Participant

    @project_subdomain

    just had the problem that on all not bbpress-related pages the title was ” ‘s “.
    When commenting out the part for “User is viewing someone else’s profile” it’s working correctly on all pages, also when viewing another profile:

    else {
    			$new_title['text'] = sprintf( esc_attr_x( "%s's", 'User viewing another users profile', 'bbpress' ), get_userdata( bbp_get_user_id() )->display_name );
           }

    fyi new occurred, just had a wordpress update recently


    Robkk
    Moderator

    @robkk

    It is weird that you got this new issue. I just tested the snippet again on my WAMP server to check with the latest version of WordPress, switched to German again, and also see if it conflicts with the last code snippet I gave you, but I do not see an issue on my side.


    project_subdomain
    Participant

    @project_subdomain

    tested commenting out above part several times which gave me correct titles and wrong titles when active. Did a systematic check then by deactivating plugins one after one and custom codes one after one and reversed, also refreshed the page title via backend (no caching in use). Nothing found to make the titles correct except commenting out above part.
    I cannot reproduce it as well.


    Robkk
    Moderator

    @robkk

    Wait the original code really still doesn’t work.

    It really did work for me, and I have the latest version of WP too.

Viewing 22 replies - 1 through 22 (of 22 total)
  • You must be logged in to reply to this topic.
Skip to toolbar