Title: hide profile fields only for certain fields
Last modified: August 21, 2016

---

# hide profile fields only for certain fields

 *  Resolved [CommonEasy](https://wordpress.org/support/users/commoneasy/)
 * (@commoneasy)
 * [11 years, 11 months ago](https://wordpress.org/support/topic/hide-profile-fields-only-for-certain-fields/)
 * Hi there,
 * I use both BP 2.0.1 and the BP custom fields type plugin and i got the the links
   removed with:
 *     ```
       function remove_xprofile_links() {
           remove_filter( 'bp_get_the_profile_field_value', 'xprofile_filter_link_profile_data', 9, 2 );
       }
       add_action('bp_setup_globals', 'remove_xprofile_links');
       ```
   
 * I was wondering if you could use this to only hide the links from certain profile
   fields, like only for profile field 2, 6 & 7 ?
 * [https://wordpress.org/plugins/buddypress-xprofile-custom-fields-type/](https://wordpress.org/plugins/buddypress-xprofile-custom-fields-type/)

Viewing 7 replies - 1 through 7 (of 7 total)

 *  Plugin Author [donmik](https://wordpress.org/support/users/atallos/)
 * (@atallos)
 * [11 years, 11 months ago](https://wordpress.org/support/topic/hide-profile-fields-only-for-certain-fields/#post-4984990)
 * Hi,
 * I believe the only way to do this is rewrite the function responsible of create
   buddypress links, you need to use the following code and delete the previous:
 *     ```
       /**
        * This is the custom filter to create links
        */
       function my_xprofile_filter_link_profile_data( $field_value, $field_type = 'textbox' ) {
           // Access the field you are going to display value.
           global $field;
           // In this array you write the ids of the fields you want to hide the link.
           $excluded_field_ids = array(2,6,7);
           // If the id of this $field is in the array, we return the value only and not the link.
           if (in_array($field->id, $excluded_field_ids))
               return $field_value;
   
       	if ( 'datebox' == $field_type )
       		return $field_value;
   
       	if ( !strpos( $field_value, ',' ) && ( count( explode( ' ', $field_value ) ) > 5 ) )
       		return $field_value;
   
       	$values = explode( ',', $field_value );
   
       	if ( !empty( $values ) ) {
       		foreach ( (array) $values as $value ) {
       			$value = trim( $value );
   
       			// If the value is a URL, skip it and just make it clickable.
       			if ( preg_match( '@(https?://([-\w\.]+)+(:\d+)?(/([\w/_\.]*(\?\S+)?)?)?)@', $value ) ) {
       				$new_values[] = make_clickable( $value );
   
       			// Is not clickable
       			} else {
   
       				// More than 5 spaces
       				if ( count( explode( ' ', $value ) ) > 5 ) {
       					$new_values[] = $value;
   
       				// Less than 5 spaces
       				} else {
       					$search_url   = add_query_arg( array( 's' => urlencode( $value ) ), bp_get_members_directory_permalink() );
       					$new_values[] = '<a href="' . $search_url . '" rel="nofollow">' . $value . '</a>';
       				}
       			}
       		}
   
       		$values = implode( ', ', $new_values );
       	}
   
       	return $values;
       }
   
       /**
        * We remove the buddypress filter and add our custom filter.
        */
       function remove_xprofile_links() {
           // Remove the old filter.
           remove_filter( 'bp_get_the_profile_field_value', 'xprofile_filter_link_profile_data', 9, 2 );
           // Add your custom filter.
           add_filter( 'bp_get_the_profile_field_value', 'my_xprofile_filter_link_profile_data', 9, 2);
       }
       add_action('bp_setup_globals', 'remove_xprofile_links');
       ```
   
 * Try it and get in touch if this does not work.
 *  Thread Starter [CommonEasy](https://wordpress.org/support/users/commoneasy/)
 * (@commoneasy)
 * [11 years, 11 months ago](https://wordpress.org/support/topic/hide-profile-fields-only-for-certain-fields/#post-4985026)
 * Hi man! sorry for the late response, i just tested your code and it works perfect!
   awesome 🙂
 *  [Netz](https://wordpress.org/support/users/netz/)
 * (@netz)
 * [11 years, 11 months ago](https://wordpress.org/support/topic/hide-profile-fields-only-for-certain-fields/#post-4985028)
 * Any chance of a rewrite of this … To remove or hide the “HOME” link in BuddyPress
   Group?
 * And some help in where to add this what file between what lined?
    Thanks Good
   Friendly People
 *  Plugin Author [donmik](https://wordpress.org/support/users/atallos/)
 * (@atallos)
 * [11 years, 11 months ago](https://wordpress.org/support/topic/hide-profile-fields-only-for-certain-fields/#post-4985029)
 * Hi, this code has nothing to do with what you want to achieve…
 *  [eberger3](https://wordpress.org/support/users/eberger3/)
 * (@eberger3)
 * [11 years, 6 months ago](https://wordpress.org/support/topic/hide-profile-fields-only-for-certain-fields/#post-4985138)
 * It would be really cool if the
 * `$excluded_field_ids`
 * array could be populated by the admin via a the plugins settings page with checkboxes
   like:
 * > Select which fields you do **not** want to be linked.
   > Available fields:
   > [ ] Field 1
   >  [x] Field 2 [ ] Field 3 [x] Field 4 [x] Field 5
   > [SUBMIT]
 * would trigger your new function above with:
 * `$excluded_field_ids = array(2,4,5);`
 * I think a lot of people would find this type of flexibility useful.
 * Thoughts?
 *  Plugin Author [donmik](https://wordpress.org/support/users/atallos/)
 * (@atallos)
 * [11 years, 6 months ago](https://wordpress.org/support/topic/hide-profile-fields-only-for-certain-fields/#post-4985139)
 * You can request this feature to buddypress team, maybe they consider it for next
   updates.
 *  [borisj](https://wordpress.org/support/users/borisj/)
 * (@borisj)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/hide-profile-fields-only-for-certain-fields/#post-4985146)
 * Thanks for this code [@donmik](https://wordpress.org/support/users/donmik/). 
   I just had to adjust it a little bit to work for me (see filters at the end)
 *     ```
       /* ------------------------------------------------------------------------- *
        *  Removing specific field links automatically created in a BP member’s profile https://wordpress.org/support/topic/hide-profile-fields-only-for-certain-fields#post-5667106
       /* ------------------------------------------------------------------------- */
       /**
        * This is the custom filter to create links
        */
       function my_xprofile_filter_link_profile_data( $field_value, $field_type = 'textbox' ) {
           // Access the field you are going to display value.
           global $field;
           // In this array you write the ids of the fields you want to hide the link.
           $excluded_field_ids = array(1,264,265,268);
           // If the id of this $field is in the array, we return the value only and not the link.
           if (in_array($field->id, $excluded_field_ids))
               return $field_value;
       	if ( 'datebox' == $field_type )
       		return $field_value;
       	if ( !strpos( $field_value, ',' ) && ( count( explode( ' ', $field_value ) ) > 5 ) )
       		return $field_value;
       	$values = explode( ',', $field_value );
       	if ( !empty( $values ) ) {
       		foreach ( (array) $values as $value ) {
       			$value = trim( $value );
   
       			// If the value is a URL, skip it and just make it clickable.
       			if ( preg_match( '@(https?://([-\w\.]+)+(:\d+)?(/([\w/_\.]*(\?\S+)?)?)?)@', $value ) ) {
       				$new_values[] = make_clickable( $value );
       			// Is not clickable
       			} else {
   
       				// More than 5 spaces
       				if ( count( explode( ' ', $value ) ) > 5 ) {
       					$new_values[] = $value;
   
       				// Less than 5 spaces
       				} else {
       					$search_url   = add_query_arg( array( 's' => urlencode( $value ) ), bp_get_members_directory_permalink() );
       					$new_values[] = '<a href="' . $search_url . '" rel="nofollow">' . $value . '</a>';
       				}
       			}
       		}
   
       		$values = implode( ', ', $new_values );
       	}
   
       	return $values;
       }
       /**
        * We remove the buddypress filter and add our custom filter.
        */
       function remove_xprofile_links() {
           remove_filter( 'bp_get_the_profile_field_value', 'xprofile_filter_link_profile_data', 9, 2 );
       }
       add_action('bp_setup_globals', 'remove_xprofile_links');
           // Add your custom filter.
           add_filter( 'bp_get_the_profile_field_value', 'my_xprofile_filter_link_profile_data', 9, 2);
       ```
   

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘hide profile fields only for certain fields’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/buddypress-xprofile-custom-fields-
   type.svg)
 * [Buddypress Xprofile Custom Fields Type](https://wordpress.org/plugins/buddypress-xprofile-custom-fields-type/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/buddypress-xprofile-custom-fields-type/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/buddypress-xprofile-custom-fields-type/)
 * [Active Topics](https://wordpress.org/support/plugin/buddypress-xprofile-custom-fields-type/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/buddypress-xprofile-custom-fields-type/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/buddypress-xprofile-custom-fields-type/reviews/)

 * 7 replies
 * 5 participants
 * Last reply from: [borisj](https://wordpress.org/support/users/borisj/)
 * Last activity: [11 years, 1 month ago](https://wordpress.org/support/topic/hide-profile-fields-only-for-certain-fields/#post-4985146)
 * Status: resolved