Better member type directory title for BuddyPress
Are you using BuddyPress member types on your site? If yes, you might have noticed the issue with member type directory title. In our forum, one of our members asked about it. Since I thought It may benefit more people, here is the code with an example.
Screenshot:- Member type directory title default
Note the page title, for Teachers member type directory, It is still showing "Members"
Screenshot 2:- Updated Member type directory title
Note the title, Now it uses the name of the registered member type in directory title.
Code:-
You can put the following code to your bp-custom.php or your theme's functions.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | /** * Modify members directory title for the current member type * * @param array $title title parts * * @return array */ function buddydev_modify_member_type_directory_title( $title ) { if ( ! bp_is_members_directory() ) { return $title; } $member_type = bp_get_current_member_type(); if ( ! $member_type ) { return $title; } $type_object = bp_get_member_type_object( $member_type ); $sep = apply_filters( 'document_title_separator', '-' ); // we are reusing the buddypress()->pages->members->id page's title, // you can call get_post() over it and do any extra manipulation $title['title'] = $title['title'] . ' ' . $sep . ' ' . $type_object->labels['name']; return $title; } add_filter( 'document_title_parts', 'buddydev_modify_member_type_directory_title', 1000 ); |
Enjoy!