Tagged: buddypress, member type, meta title
Hi!
With reference to the BP Member Type Generator plugin (https://wordpress.org/plugins/bp-member-type-generator/)
Is it possible to insert the exact phrase assigned to member type in the Meta Title of the profile page?
On my site default profile tab is ‘member profile’ instead of activity. The meta title for profile / default page of members looks like as follows :
Lavish Dhand – Sitename
Now for the sake of example lets say I have member types :
1 – Student
2 – TeacherI wish the meta title to become :
Lavish Dhand – Student – Sitename OR Student – Lavish Dhand – Sitename
and
Brajesh Singh – Teacher – Sitename – OR Teacher – Brajesh Singh – Sitename
Is the above possible? How?
Thank you for the help 🙂
I am testing BP Member Type Generator plugin with
1- Xprofile Member Type Field
and
2 – Conditional Profile Fields for BuddyPress
While creating a multi-select field, I am choosing it to be hidden if chosen Member Type is ‘Type1’ (Member Type is very first field in registration form).
This multi-select field is still visible if user chooses ‘Type1’.
I am sending you a private message with screen shot and url.
Thank you for the help.
Hi Lavish,
Thank you for posting. I am posting reply of your first question. Please try the following code in your bp-custom.php file and let me know if it works or not.
function buddydev_modify_profile_page_title( $new_title, $title, $sep, $seplocation ) { if ( bp_is_user_profile() && bp_current_action() == 'public' ) { $member_type = bp_get_member_type( bp_displayed_user_id() ); if ( $member_type ) { $new_title = ucfirst( $member_type ) . ' ' . $sep . ' ' . $new_title; } } return $new_title; } add_filter( 'bp_modify_page_title', 'buddydev_modify_profile_page_title', 10, 4 );
Thank You
Ravi- This reply was modified 8 years, 5 months ago by Ravi.
Hello @ravisharma
Thanks for the reply. Can I use the code in function.php instead of bp-custom.php?
Also, I am already fixing my BP Titles for Yoast SEO plugin with the following code in my function.php. Hopefully the 2 codes won’t mess up with each other.
‘
function wpseo_fix_title_buddypress($title) {
// Check if we are in a buddypress page
if ( function_exists( ‘buddypress’) && ( !empty( buddypress()->displayed_user->id ) || !empty( buddypress()->current_component ) ) ) {
$bp_title_parts = bp_modify_document_title_parts();// let’s rebuild the title here
$title = $bp_title_parts[‘title’] . ‘ ‘ . $title;
}
return $title;
}
add_filter( ‘wpseo_title’, ‘wpseo_fix_title_buddypress’);‘
Thank you for the help
Hi Lavish,
Yes, You can use the code in your current theme’s functions.php file. But in place of your code use the following code and let me know if it works or not.
function buddydev_disable_seo_title() { if ( function_exists( 'is_buddypress') && is_buddypress() && class_exists( 'WPSEO_Frontend' ) ) { $instance = WPSEO_Frontend::get_instance(); remove_filter( 'wp_title', array( $instance, 'title' ), 15, 3 ); remove_filter( 'pre_get_document_title', array( $instance, 'title' ), 15 ); } } add_action( 'bp_template_redirect', 'buddydev_disable_seo_title' );
Thank You
RaviHi Lavish,
Have you kept the code from Ravi’s previous reply?HI Lavish,
Please put this code in your bp-custom.php and visit The Users profilefunction buddydev_modify_profile_page_title( $title_parts ) { if ( bp_is_user_profile() && bp_current_action() == 'public' ) { $member_type = bp_get_member_type( bp_displayed_user_id() ); if ( $member_type ) { $memeber_type_object = bp_get_member_type_object( $member_type ); array_unshift( $title_parts, $memeber_type_object->labels['singular_name'] ); } } return $title_parts; } add_filter( 'bp_get_title_parts', 'buddydev_modify_profile_page_title' );
Please let me know if it works for you or not?
Hats Off! @sbrajesh thank you @ravisharma I can’t thank you enough guys. The following code worked perfectly.
// First fix BP titles for Yoast using Ravi’s code
function buddydev_disable_seo_title() {
if ( function_exists( ‘is_buddypress’) && is_buddypress() && class_exists( ‘WPSEO_Frontend’ ) ) {
$instance = WPSEO_Frontend::get_instance();remove_filter( ‘wp_title’, array( $instance, ‘title’ ), 15, 3 );
remove_filter( ‘pre_get_document_title’, array( $instance, ‘title’ ), 15 );
}}
add_action( ‘bp_template_redirect’, ‘buddydev_disable_seo_title’ );// Now insert ‘Member Type Phrase’ in BP Titles
function buddydev_modify_profile_page_title( $title_parts ) {
if ( bp_is_user_profile() && bp_current_action() == ‘public’ ) {
$member_type = bp_get_member_type( bp_displayed_user_id() );
if ( $member_type ) {
$memeber_type_object = bp_get_member_type_object( $member_type );
array_unshift( $title_parts, $memeber_type_object->labels[‘singular_name’] );
}
}return $title_parts;
}
add_filter( ‘bp_get_title_parts’, ‘buddydev_modify_profile_page_title’ );
The topic ‘ [Resolved] insert 'BP Member Type Phrase' in Meta Title’ is closed to new replies.