@abdu11ah
You can try this code snippet, which will write to /wp-content/debug.log the source of your redirects.
add_filter( 'x_redirect_by', 'wp_redirect_custom_log', 10, 3 );
function wp_redirect_custom_log( $x_redirect_by, $location, $status ) {
$traces = debug_backtrace( DEBUG_BACKTRACE_PROVIDE_OBJECT );
$plugin_trace = array();
foreach ( $traces as $trace ) {
if( isset( $trace['file'] )) {
if ( strpos( $trace['file'], '/plugins/' ) > 0 ) {
$file = explode( '/plugins/', $trace['file'] );
if( substr( $file[1], 0, 22 ) != 'wp_redirect_custom_log' ) {
$plugin_trace[] = $file[1] . ':' . $trace['line'];
}
}
if ( strpos( $trace['file'], '/themes/' ) > 0 ) {
$file = explode( '/themes/', $trace['file'] );
$plugin_trace[] = 'T: ' . $file[1] . ':' . $trace['line'];
}
if ( strpos( $trace['file'], '/wp-includes/' ) > 0 ) {
$file = explode( '/wp-includes/', $trace['file'] );
$plugin_trace[] = 'WP: ' . $file[1] . ':' . $trace['line'];
}
}
}
$trace = date_i18n( 'Y-m-d H:i:s ', current_time( 'timestamp' ));
$trace .= 'redirect by ' . $x_redirect_by . ', ' . $location . ', ' . $status . ', ';
$trace .= 'stack trace: ' . implode( ', ', $plugin_trace );
file_put_contents( WP_CONTENT_DIR . '/debug.log', $trace . chr(13), FILE_APPEND );
return $x_redirect_by;
}
Add the code snippet to your active theme’s/child-theme’s functions.php file
or use the “Code Snippets” plugin.
https://wordpress.org/plugins/code-snippets/
Hi @abdu11ah
This thread has been inactive for a while so we’re going to go ahead and mark it Resolved.
Please feel free to re-open this thread if any other questions come up and we’d be happy to help. 🙂
Regards