Skip to:
Content
Pages
Categories
Search
Top
Bottom

Opening links in Activity in a new window


  • mjhpersonnel
    Participant

    @mjhpersonnel

    I have reviewed all the posts on here and through searching online and still can’t solve this problem.

    All I want to do is ensure that any links posted by users in the Activity feed open in a new window. Opening in the same window (as BP seems to do by default) is not great. I can see this topic has been mentioned by others for years now.

    Has anyone got an ideas?

    I have tried adding code to bp-custom.php but this does not work.

    Thanks in advance.

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

  • Varun Dubey
    Participant

    @vapvarun


    mjhpersonnel
    Participant

    @mjhpersonnel

    Thanks @vapvarun

    Should this be added to functions.php or bp-custom.php? Or somewhere else?

    Thanks again


    wbcomdesigns
    Participant

    @wbcomdesigns

    @mjhpersonnel better to use code snippet plugin, it’s easy to manage


    mjhpersonnel
    Participant

    @mjhpersonnel

    Thanks both. This works perfect and links in the activity section now open in a new page. Top stuff. πŸ™‚


    epgb101
    Participant

    @epgb101

    Hi
    I pasted https://pastebin.com/Z3z7s87j into a code snippet and it does nothing WP 5.7.1 – I set it to Run Snippet Everywhere.

    Not sure why this would not be standard option in Buddypress. In seconds all my users are off and outside my site which they don’t want to be! They want to stay on it – not have to keep finding the URL to my social network.

    Any ideas how to do this in activity stream?

    Thanks.


    Varun Dubey
    Participant

    @vapvarun

    @epgb101 try to use raw code inside code snippet plugin

    // open all buddypress activity links in new tab
    function vap_activity_links_target_blank($link) {
    	$link = str_replace(' rel="nofollow ugc"','target="_blank" rel="nofollow ugc"',$link);
        return $link;
    
    }
    
    add_filter('bp_get_activity_content','vap_activity_links_target_blank',20);
    add_filter('bp_get_activity_content_body','vap_activity_links_target_blank',20);
    add_filter('bp_get_activity_parent_content','vap_activity_links_target_blank',20);
    add_filter('bp_get_activity_latest_update','vap_activity_links_target_blank',20);
    add_filter('bp_get_activity_latest_update_excerpt','vap_activity_links_target_blank',20);
    add_filter('bp_get_activity_feed_item_description','vap_activity_links_target_blank',20);
    add_filter('bp_get_activity_feed_item_description','vap_activity_links_target_blank',20);

    epgb101
    Participant

    @epgb101

    I can’t believe it – it worked! – what is ‘raw code’ as opposed to what I copied/pasted before?

    I searched for this for a whole day and found nothing useful surely more people need this.

    Thank you very much. πŸ™‚


    iamthewebb
    Participant

    @iamthewebb

    Glad you got it sorted, I think the reason this isn’t more widely used is due to accessibility, the w3 advises against using a new window except for certain circumstance to avoid a negative impact on those with accessibility needs.


    epgb101
    Participant

    @epgb101

    I see – I did not know that – thank you for letting me know.

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