Skip to:
Content
Pages
Categories
Search
Top
Bottom

Profile URLs

  • Profile photo of wakeatlas
    wakeatlas
    Participant

    @wakeatlas

    I have profile field that contains URLs but it open in the same window. How can I make this open to the new window?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Profile photo of wakeatlas
    wakeatlas
    Participant

    @wakeatlas

    HELLO??

    Profile photo of Andrew
    Andrew
    Participant

    @snd26

    You need to add the target=”_blank” attribute to the profile field value anchors.

    I think the best way to do this is by using str_replace. Add this to your functions.php or bp-custom.php

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

    I’ve tested this and it works. This should open a new browser window/tab for all profile fields that have a URL’s.

    Profile photo of Andrew
    Andrew
    Participant

    @snd26

    This one is probably better:

    function profile_target_blank( $field_value, $field_type, $field_id ){
    
        if($field_type == 'url')  { 
    	
              $field_value = str_replace('rel="nofollow"', 'rel="nofollow" target="_blank"', $field_value);
       
        }
    	
        return $field_value;
    }
    add_filter('bp_get_the_profile_field_value', 'profile_target_blank', 11, 3);
    Profile photo of Venutius
    Venutius
    Participant

    @venutius

    Just tried this and it works great, thanks for the code.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Profile URLs’ is closed to new replies.
Skip to toolbar