I’d suggest you do this as follows:
there is a ‘hook’ that you show above called ‘<?php do_action( ‘bbp_template_before_single_topic’ ); ?>’
This tells bbpress to do any action that is added at that point.
so adding a hook will mean that the function is called at that point.
The following code should go in your child theme functions file, or use the code snippets plugin
add_action ( 'bbp_template_before_single_topic' , 'rew_back' );
function rew_back () {
$text = 'click to go back' ;
if (bbp_get_topic_forum_id() == '25') $href = home_url( '/forum/domestics/' ) ;
if (bbp_get_topic_forum_id() == '33') $href = home_url( '/forum/commercial/' ) ;
//where to go if page not there
else $href = home_url( '/login/' ) ;
echo '<a class="button" href ="'.$href.'">'.$text.'</a>' ;
}
so each forum will need a line.