Last active
December 2, 2021 03:28
-
-
Save junaidbhura/a7c83a2efb323c19d3da80b5faf8fe86 to your computer and use it in GitHub Desktop.
WordPress fallback post instead of 404
This file contains hidden or 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
<?php | |
add_action( | |
'wp', | |
function () { | |
global $wp_query; | |
if ( ! $wp_query->is_main_query() || ! $wp_query->is_404() ) { | |
return; | |
} | |
$wp_query = new WP_Query( | |
[ | |
'post_type' => 'page', | |
'p' => 2, | |
] | |
); | |
remove_action( 'template_redirect', 'redirect_canonical' ); | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment