Skip to content

Instantly share code, notes, and snippets.

@mi-ca
Created August 16, 2017 12:16
Show Gist options
  • Select an option

  • Save mi-ca/868ca24a31eada03a5807d4100d75038 to your computer and use it in GitHub Desktop.

Select an option

Save mi-ca/868ca24a31eada03a5807d4100d75038 to your computer and use it in GitHub Desktop.
Wordpress disable useless Routes
<?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