Skip to content

Instantly share code, notes, and snippets.

@avenirer
Last active November 19, 2018 15:05
Show Gist options
  • Save avenirer/697e3ae47efc8cf3640a6274ba872431 to your computer and use it in GitHub Desktop.
Save avenirer/697e3ae47efc8cf3640a6274ba872431 to your computer and use it in GitHub Desktop.
Debug WordPress rewrite rules
<?php
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