Skip to content

Instantly share code, notes, and snippets.

@jrevillini
Last active Mar 18, 2021
Embed
What would you like to do?
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');
@jrevillini
Copy link
Author

jrevillini commented Jul 15, 2019

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