Skip to content

Instantly share code, notes, and snippets.

@jrevillini
Last active March 18, 2021 21:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jrevillini/7f38ee887d7e6919cfc31c6a7e2cc514 to your computer and use it in GitHub Desktop.
Save jrevillini/7f38ee887d7e6919cfc31c6a7e2cc514 to your computer and use it in GitHub Desktop.
BBPress / REDIRECT REPLY POSTS TO TOPIC WITH REPLY ANCHOR
<?php
// ---------------------------------------- REDIRECT REPLY POSTS TO TOPIC WITH REPLY ANCHOR
function jrevillini_reply_redirect( $wp_query ) {
if ( !function_exists('bbp_get_reply_url') ) return; // skip this if bbpress not active
if ( !isset($wp_query->query['reply']) ) return; // skip if not a bbpress reply page
if ( isset($wp_query->query['edit']) ) return; //skip if we are EDITING a bbpress reply
wp_safe_redirect( bbp_get_reply_url( $wp_query->query['reply'] ) );
}
add_action('pre_get_posts', 'jrevillini_reply_redirect');
@zee3h
Copy link

zee3h commented Mar 18, 2021

Hi James - thanks for this code! I've added it to Code Snippets but it seems to generate a redirect loop when a reply URL is clicked, e.g. https://300hours.com/reply/new-here-dont-be-shy-say-hello-here-and-earn-your-first-badge-4/

Any idea on how to solve?

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