BuddyDev

Search

[Resolved] Add the member type value (i.e. student, teacher ecc) in the member page title

  • Participant
    Level: Initiated
    Posts: 3
    Elio on #5267

    Hi!
    Is it possible to add the member type value (i.e. student, teacher ecc) in the member page title, in order to have for example:
    “Members: Teachers”
    instead of
    “Member”

    when I’m in sitename.com/members/type/Teachers/

    Thanks in advance

  • Keymaster
    (BuddyDev Team)
    Posts: 24706
    Brajesh Singh on #5270

    Hi Elio,
    Welcome to BuddyDev.

    Please put this code in your bp-custom.php or in your theme’s functions.php and It will do

    
    function buddydev_append_membertype_in_directory_title( $bp_title, $old_title ) {
    
    	$member_type = bp_get_current_member_type();
    
    	if ( ! $member_type ) {
    		return $bp_title;
    	}
    
    	$type_object = bp_get_member_type_object( $member_type );
    
    	$bp_title['title'] = $bp_title['title'] . ': ' . $type_object->labels['singular_name'] ;
    	return $bp_title;
    }
    add_filter( 'bp_modify_document_title_parts', 'buddydev_append_membertype_in_directory_title', 10, 2 );
    

    Hope that helps.
    Regards
    Brajesh

  • Participant
    Level: Initiated
    Posts: 3
    Elio on #5276

    Hi Brajesh,
    Thanks for the quick response.
    I tried in both bp-custom.php and functions.php files, also with standard template and with all the plugin deactivated (except for BuddyPress Member Type Generator and Buddypress) but seems not change the member page title.. some workaround that I can do to find the problem?

    Thanks again
    Elio

  • Keymaster
    (BuddyDev Team)
    Posts: 24706
    Brajesh Singh on #5277

    Hi Elio,
    Thank you for the detailed reply.

    It is for the title in the browser(The attribute). Are you referring to Directory title inside the page?

  • Participant
    Level: Initiated
    Posts: 3
    Elio on #5278

    I’m referring to the page title, that for buddypress is “member” for member page, site wide activity for the activity page and so on.. (the title usually shown after the header before the body of the page)

  • Keymaster
    (BuddyDev Team)
    Posts: 24706
    Brajesh Singh on #5280

    Hi Elio,
    Please add this

    
    
    function buddydev_append_membertype_in_page_title( $title, $component ) {
    
    	if ( $component != 'members' ) {
    		return $title;
    	}
    
    	$member_type = bp_get_current_member_type();
    
    	if ( ! $member_type ) {
    		return $title;
    	}
    
    	$type_object = bp_get_member_type_object( $member_type );
    
    	$title = $title . ': ' . $type_object->labels['singular_name'] ;
    
    	return $title;
    
    }
    add_filter( 'bp_get_directory_title', 'buddydev_append_membertype_in_page_title' , 10, 2 );
    
    

    and let me know if it works for you or not?

    Thank you
    Brajesh

  • Participant
    Level: Initiated
    Posts: 4
    Jon on #17047

    Hi sorry to drag up an old thread but..
    The code works great for my needs, is there anyway to remove the members : part and just leave the page title? e.g. my page title currently says Members : Artwork and I need it to just say Artwork. Also I’m trying this on the member type generator, I will be purchasing the pro, will it also work on that?
    Thanks Jon

    • This reply was modified 6 years, 3 months ago by Jon.
  • Keymaster
    (BuddyDev Team)
    Posts: 24706
    Brajesh Singh on #17052

    Hi Jon,
    Welcome to BuddyDev.

    You can change this line

    
    $bp_title['title'] = $bp_title['title'] . ': ' . $type_object->labels['singular_name'] ;
    
    

    to

    
    $bp_title['title'] =  $type_object->labels['singular_name'] ;
    
    

    That will do it.

    Thank you for considering the member type generator and pro. yes, It will work for both.

    Regards
    Brajesh

  • Participant
    Level: Initiated
    Posts: 4
    Jon on #17060

    Thanks Brajesh, worked perfectly. 🙂

  • Keymaster
    (BuddyDev Team)
    Posts: 24706
    Brajesh Singh on #17061

    You are welcome. Glad it worked.

The topic ‘ [Resolved] Add the member type value (i.e. student, teacher ecc) in the member page title’ is closed to new replies.

This topic is: resolved