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');
@blogxkomo
Copy link

Where this code must to input?
Can you help me

@jrevillini
Copy link
Author

You can put it in functions.php but it may be easier for you to use the code snippets plugin like this: http://tinyurl.com/y49p67as

@blogxkomo
Copy link

but i've already add that code to functions.php, and then my website down can't to be access.

i don't know why it's happened

@jrevillini
Copy link
Author

If you give me the error generated in your error_log file I'm sure we can troubleshoot this. I'm pretty sure the code works as others have implemented it with success.

@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