Better group type directory title for BuddyPress
A few days ago, we discussed about having better member type directory title. Today, let us see the same for the group types directory title. In this post, we will see how to improve the directory title for the group types directory:-
Problem:-
By default, BuddyPress does not update the directory title to reflect current group type. You may see it in the following screenshot.
As you see, we are looking at the group type teams directory but it is still showing only "Groups" in the title.
Solution:-
You can put the following code in your bp-custom.php or in 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 groups directory title for the current group type * * @param array $title title parts * * @return array */ function buddydev_modify_group_type_directory_title( $title ) { if ( ! bp_is_groups_directory() ) { return $title; } $group_type = bp_get_current_group_directory_type(); if ( ! $group_type ) { return $title; } $type_object = bp_groups_get_group_type_object( $group_type ); $sep = apply_filters( 'document_title_separator', '-' ); // we are reusing the buddypress()->pages->groups->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_group_type_directory_title', 1000 ); |
Here is the final result.
Enjoy!