Created
August 16, 2017 12:16
-
-
Save mi-ca/868ca24a31eada03a5807d4100d75038 to your computer and use it in GitHub Desktop.
Wordpress disable useless Routes
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 | |
| /** | |
| * Disable routes | |
| */ | |
| /** | |
| * disable useless routes | |
| * prevent user to call routes that you don't skin ;) | |
| * comment the lines you skin // | |
| */ | |
| function disable_useless_routes() { | |
| if ( | |
| is_feed() || | |
| is_author() || | |
| // is_archive() || | |
| is_attachment() || | |
| is_search() || | |
| is_category() || | |
| // is_single() || | |
| // is_page() || | |
| is_tax() || | |
| is_tag() | |
| ){ | |
| global $wp_query; | |
| $wp_query->set_404(); | |
| status_header(404); | |
| } else { | |
| redirect_canonical(); | |
| } | |
| } | |
| remove_filter('template_redirect', 'redirect_canonical'); | |
| add_action('template_redirect', 'disable_useless_routes'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment