Skip to content

Instantly share code, notes, and snippets.

@rmpel
Last active December 9, 2015 13:12
Show Gist options
  • Save rmpel/5466f22cf750a53983d7 to your computer and use it in GitHub Desktop.
Save rmpel/5466f22cf750a53983d7 to your computer and use it in GitHub Desktop.
See what function is causing a redirect in WordPress
<?php
add_filter('wp_redirect', 'clarify_redirect');
function clarify_redirect( $url ) {
$callers = debug_backtrace();
foreach ($callers as $i => $caller) {
header("X-Caller-{$i}: ". $caller['function']);
}
return $url;
}
@rmpel
Copy link
Author

rmpel commented Dec 9, 2015

This will hook into the wp_redirect function and provide information in the headers of the page that is redirecting, not the page that WordPress is redirecting to. Though the visitor will not see these extra headers unless looking for them, it is wise to only use this for debugging purposes.

You can view the headers yourself by either using a developer tool in your browser with the option "persist" on, or you can use cURL on the command line of your OS (Mac OS X or Linux support cURL out of the box, for Windows you might need to install it first - not covered here)

curl -D - "http://yourdomain.com/your-redirecting-page"

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