Forked from yunusga/gist:33cf0ba9e311e12df4046722e93d4123
Created
October 27, 2020 12:56
-
-
Save montrealist/18e000c022333832719d4f524842d6c1 to your computer and use it in GitHub Desktop.
Debug WordPress 404 issues (permalinks, rewrite rules, etc.)
This file contains 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
/* Produces a dump on the state of WordPress when a not found error occurs */ | |
/* useful when debugging permalink issues, rewrite rule trouble, place inside functions.php */ | |
ini_set( 'error_reporting', -1 ); | |
ini_set( 'display_errors', 'On' ); | |
echo '<pre>'; | |
add_action( 'parse_request', 'debug_404_rewrite_dump' ); | |
function debug_404_rewrite_dump( &$wp ) { | |
global $wp_rewrite; | |
echo '<h2>rewrite rules</h2>'; | |
echo var_export( $wp_rewrite->wp_rewrite_rules(), true ); | |
echo '<h2>permalink structure</h2>'; | |
echo var_export( $wp_rewrite->permalink_structure, true ); | |
echo '<h2>page permastruct</h2>'; | |
echo var_export( $wp_rewrite->get_page_permastruct(), true ); | |
echo '<h2>matched rule and query</h2>'; | |
echo var_export( $wp->matched_rule, true ); | |
echo '<h2>matched query</h2>'; | |
echo var_export( $wp->matched_query, true ); | |
echo '<h2>request</h2>'; | |
echo var_export( $wp->request, true ); | |
global $wp_the_query; | |
echo '<h2>the query</h2>'; | |
echo var_export( $wp_the_query, true ); | |
} | |
add_action( 'template_redirect', 'debug_404_template_redirect', 99999 ); | |
function debug_404_template_redirect() { | |
global $wp_filter; | |
echo '<h2>template redirect filters</h2>'; | |
echo var_export( $wp_filter[current_filter()], true ); | |
} | |
add_filter ( 'template_include', 'debug_404_template_dump' ); | |
function debug_404_template_dump( $template ) { | |
echo '<h2>template file selected</h2>'; | |
echo var_export( $template, true ); | |
echo '</pre>'; | |
exit(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment