Removing WordPress Endpoints

One of my gripes about WordPress is how out-of-control routing can be. It’s difficult to anticipate all the various endpoints WordPress will happy throw responses at.

While I don’t have a solution for that, an old post on Better WP shows how to fully disable some common WordPress endpoints.

Here’s a simple example snippet to disable search results:

function kill_templates() {
    global $wp_query, $post;
    if (is_search()) {
        $wp_query->set_404();
    }
}
add_action('template_redirect', __NAMESPACE__ . '\kill_templates');

Leave a comment