Last active
March 18, 2021 21:51
-
-
Save jrevillini/7f38ee887d7e6919cfc31c6a7e2cc514 to your computer and use it in GitHub Desktop.
BBPress / REDIRECT REPLY POSTS TO TOPIC WITH REPLY ANCHOR
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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'); |
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
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
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.
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
Where this code must to input?
Can you help me