BuddyDev

Search

[Resolved] insert 'BP Member Type Phrase' in Meta Title

  • Participant
    Level: Enlightened
    Posts: 60
    lavish on #4436

    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 – Teacher

    I 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 🙂

  • Participant
    Level: Enlightened
    Posts: 60
    lavish on #4481

    @sbrajesh

    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.

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 3115
    Ravi on #4494

    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, 4 months ago by Ravi.
  • Participant
    Level: Enlightened
    Posts: 60
    lavish on #4496

    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

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 3115
    Ravi on #4499

    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
    Ravi

  • Participant
    Level: Enlightened
    Posts: 60
    lavish on #4501

    Hello Ravi,

    So, I removed my old code and used your latest one. The member type is not added to the title. Your code seems to be fixing Yoast (exactly like my old code did) but it is not adding anything new.

    Thanks

  • Keymaster
    (BuddyDev Team)
    Posts: 24599
    Brajesh Singh on #4504

    Hi Lavish,
    Have you kept the code from Ravi’s previous reply?

  • Participant
    Level: Enlightened
    Posts: 60
    lavish on #4505

    Hello Brajesh,

    Yes, I have tried both with and without the previous code. It is fixing Yoast but not adding the desired Member Type Phrase.

    Thanks for the help 🙂

  • Keymaster
    (BuddyDev Team)
    Posts: 24599
    Brajesh Singh on #4506

    HI Lavish,
    Please put this code in your bp-custom.php and visit The Users profile

    
    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' );
    
    

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

  • Participant
    Level: Enlightened
    Posts: 60
    lavish on #4514

    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.

This topic is: resolved