Skip to content

Instantly share code, notes, and snippets.

@johanguse
Last active January 6, 2022 12:52
Show Gist options
  • Save johanguse/161acf41f049f6bbe9b5f30f3643fe04 to your computer and use it in GitHub Desktop.
Save johanguse/161acf41f049f6bbe9b5f30f3643fe04 to your computer and use it in GitHub Desktop.
Debug rewrite rules on Wordpress
// Debug Rewrite Rules in Wordpress
function debug_rewrite_rules() {
global $wp, $template, $wp_rewrite;
echo '<pre>';
echo 'Request: ';
echo empty($wp->request) ? "None" : esc_html($wp->request) . PHP_EOL;
echo 'Matched Rewrite Rule: ';
echo empty($wp->matched_rule) ? None : esc_html($wp->matched_rule) . PHP_EOL;
echo 'Matched Rewrite Query: ';
echo empty($wp->matched_query) ? "None" : esc_html($wp->matched_query) . PHP_EOL;
echo 'Loaded Template: ';
echo basename($template);
echo '</pre>' . PHP_EOL;
echo '<pre>';
print_r($wp_rewrite->rules);
echo '</pre>';
}
add_action( 'wp_head', 'debug_rewrite_rules' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment