Using WordPress Page Titles for BuddyPress Directory Page heading & Titles
If you are using BuddyPress, you might have already noticed it. The directory titles are hard coded and can not be changed by just changing the page title. You can still change it by translating the languages file.
While Building our upcoming BuddyPress theme, Community Builder, I wanted the site admins to have more freedom. I experimented a little and It worked. Here is the code that you can put in your bp-custom.php. Once you have put the code, BuddyPress directory will use your WordPress page title instead of the hard coded title.
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 30 31 32 33 34 35 36 37 38 | //Change the Heading function buddydev_change_page_heading() { if ( ! bp_is_theme_compat_active() ) { return ; } global $wp_query, $post; if ( ! is_singular() ) { return ; } $post_id = get_queried_object_id(); $current_post = get_post( $post_id ); // Set the $post global. $post->post_title = $current_post->post_title; // Copy the new post global into the main $wp_query. $wp_query->post = $post; $wp_query->posts = array( $post ); } add_action( 'bp_template_include_reset_dummy_post_data', 'buddydev_change_page_heading', 100 ); //Update the Broser page title too function buddydev_update_page_title( $bp_title_parts ) { if ( bp_is_directory() || bp_is_register_page() || bp_is_activation_page() ) { // No current component (when does this happen?). $bp_title_parts = array( get_the_title( get_queried_object_id() ) ); } return $bp_title_parts; } add_filter( 'bp_get_title_parts', 'buddydev_update_page_title' ); |
This Code allows you to change the title of the following BuddyPress pages:-
- Members Directory page
- Groups directory page
- Blogs Directory
- Activity
- Registration Page
- Account activation page
There is already a ticket about the issue on BuddyPress trac and It seems something similar is going to be part of BuddyPress 2.6.0. You may check the ticket here. Enjoy your weekend. Next week, We will be back with more BuddyPress tips 🙂
The link to the ticket is broken.
Thank you Renato. I have updated the link now.
Thanks a lot for your help … Could I use the code and add the code to —- child-theme folder/buddypress/bp-custom.php
Hi Eric,
Thank you.
You can put it in your theme's functions.php or the wp-content/plugins/bp-custom.php
Hope that helps.
Regards
Brajesh