Yes, you could add it to functions.php, but it may be easier for you to install the plugin Code Snippets and then paste it into a snippet like so: http://tinyurl.com/y49p67as
Oops! You are right. I created a gist for it and updated with the fix: https://gist.github.com/jrevillini/7f38ee887d7e6919cfc31c6a7e2cc514
Thanks for pointing that out. If you notice any other issues, please let me know.
BONUS: smooth scroll to the anchor point when page loads with this plugin: https://wordpress.org/plugins/page-scroll-to-id/
I coded something you can add to your functions.php file which will do this.
// ---------------------------------------- REDIRECT REPLY POSTS TO TOPIC WITH REPLY ANCHOR
function jrevillini_reply_redirect( $wp_query ) {
if ( !function_exists('bbp_get_reply_url') ) return;
if ( !isset($wp_query->query['reply']) ) return;
wp_safe_redirect( bbp_get_reply_url( $wp_query->query['reply'] ) );
}
add_action('pre_get_posts', 'jrevillini_reply_redirect');