Skip to:
Content
Pages
Categories
Search
Top
Bottom

Profile fields open URL in new tab (_blank)


  • Swissprice
    Participant

    @swissprice

    Hello,

    First of all, thank you for this great plugin which works perfectly on my website.

    In the profile fields I added “Website” so the members can add their own website URL.

    It opens in the same tab and instead I would like it to open in a new tab and this option is not available while creating the field.

    My question: in which file (of the BuddyPress plugin folder) can I add ‘target=”_blank”‘?

    Thank you in advance for your help! 🙂

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

  • danbp
    Participant

    @danbp

    Hi @swissprice,

    the field type of “Website” should be URL.

    The class who build this is defined here:
    buddypress/bp-xprofile/classes/class-bp-xprofile-field-type-url.php
    Function name is display_filter()
    The line to change is the…latest (161).

    Now be warned.
    This function is not filterable ( but i may be wrong)
    Modifying core files is not best practice as you will loose your change at next update.
    Target _blank is kind of deprecated since many years now in favor of user decision. This one just in case you absolutely want to use target argument.


    shanebp
    Moderator

    @shanebp

    There is a filter hook for displaying profile fields – so you don’t need to hack core files.

    apply_filters( 'bp_get_the_profile_field_value', $field->data->value, $field->type, $field->id );

    Use str_replace to insert your target blank string.

    function swiss_target_blank( $field_value, $field_type, $field_id ){
    	
    	if( $field_id == 123 ) { // 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);

    Swissprice
    Participant

    @swissprice

    Hello, thank you!

    I will try that and tell you if it worked. 🙂


    rmiarka
    Participant

    @rmiarka

    Hello shanebp

    thank you for this – that works very well on the members page. Is there a smiliar approach possible on the members list page?

    Kind regards,
    Ralph

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Profile fields open URL in new tab (_blank)’ is closed to new replies.
Skip to toolbar