Skip to content

Instantly share code, notes, and snippets.

@pranali333
Created August 29, 2018 11:28
Show Gist options
  • Save pranali333/149fd3480765b2c09b2a383b9c3d9d59 to your computer and use it in GitHub Desktop.
Save pranali333/149fd3480765b2c09b2a383b9c3d9d59 to your computer and use it in GitHub Desktop.
Keep the Media tab open while visiting BuddyPress group
/**
* This snippet can be used for redirecting users to the BuddyPress group Media tab when clicking on the group name.
* You can use this code under your theme's functions.php file:
*/
function bp_change_group_link( $link ) {
preg_match_all( '~<a(.*?)href="([^"]+)"(.*?)>~', $link, $matches );
$link_changed = preg_replace( "/(?<=href=(\"|'))[^\"']+(?=(\"|'))/", $matches[2][0] . apply_filters( 'rtmedia_media_tab_slug', 'media' ), $link );
return $link_changed;
}
add_filter( 'bp_get_group_link', 'bp_change_group_link' );
@pranali333
Copy link
Author

You can checkout sample output here:

group-media-tab-open-by-default

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment