Skip to:
Content
Pages
Categories
Search
Top
Bottom

BuddyPress – Profile Field – Open Link in New Window


  • jcfromkc
    Participant

    @jcfromkc

    On the Members Profile page I’d like to have the Profile Field URL open in a new window.

    I found the following article regard this issue.

    https://buddypress.org/support/topic/profile-fields-open-url-in-new-tab-_blank/

    I’ve tried the mentioned function below but its not working.

    function swiss_target_blank( $field_value, $field_type, $field_id ){
    	
    	if( $field_id == 6 ) {
    		$field_value = str_replace('rel="nofollow"', 'rel="nofollow" target="_blank"', $field_value);
    	}
    	return $field_value;
    }
    add_filter('bp_get_the_profile_field_value', 'swiss_target_blank', 11, 3);

    It works when I modify the core file located at buddypress/bp-xprofile/classes/class-bp-xprofile-field-type-url.php, line 176. I’d like to find a way to do this without editing the core.

    The article referenced above was written about 4 years ago. Has someone changed recently that would prevent the function from working?

    Can someone please point me in the right direction? Thx

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

  • David Cavins
    Keymaster

    @dcavins

    Well, you’ll have to be sure that the “Profile Field URL” field has the id of 6 on your installation. On your site, visit the Profile Fields admin at Wp Admin > Users > Profile Fields (/wp-admin/users.php?page=bp-profile-setup) and hover over the “Edit” button for the field you want to affect. The link will look something like /wp-admin/users.php?page=bp-profile-setup&mode=edit_field&group_id=1&field_id=7 showing you the field_id you want to use.


    jcfromkc
    Participant

    @jcfromkc

    Thanks for commenting. I’m using the correct field_id. I just created a new field, it was given the id of 54. When I try the following code it doesn’t work.

    function swiss_target_blank( $field_value, $field_type, $field_id ){
    	
    	if( $field_id == 54 ) { // get the field_id from edit field url in wp-admin
    
    		$field_value = str_replace('" rel="nofollow">', 'rel="nofollow" target="_blank"', $field_value);
    	}
    
    	return $field_value;
    }
    add_filter('bp_get_the_profile_field_value', 'swiss_target_blank', 11, 3);

    I tried this code in my functions.php and bp-custom.php, neither work.

    Line 176 – /plugins/buddypress/bp-xprofile/classes/class-bp-xprofile-field-type-url.php

    It seems like the way you’re suppose to target rel=”nofollow” has changed or something.

    I’m still working on this.

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.
Skip to toolbar