7

Hello guy's Please help me i install REST API plugin WP and i adding some specific route and any things it's work fine as i wont. But I want to disable default route exemple : /wp-json/ /wp-json/wp/v2/posts

2 Answers 2

12

As of Wordpress 4.7 it seems to be the following (noting 99 instead of 0):

remove_action('rest_api_init', 'create_initial_rest_routes', 99);

However this will also remove any custom content type routes. So instead you may choose to use:

add_filter('rest_endpoints', function($endpoints) {

    unset( $endpoints['/wp/v2/users'] );
    // etc

    return $endpoints;
});
4
  • there is any cleaner way to do this ? Mar 13, 2017 at 6:47
  • 2
    ....to? To do what exactly? To remove the default api routes, you can't really beat the one liner above. It's using actions and filters which is a pretty clean and abstract way to tackle modifications to core functionality
    – Chris
    Mar 13, 2017 at 9:12
  • I mean your second opinion, because when I remove the rest_api_init then it clears custom routes as well(as you describe also). Basically I need to disable the default routes and add custom routes. Mar 13, 2017 at 9:43
  • are we need to unset all the default routes one by one ? are we having any cleaner solution for that ? to be precise : I asked new question stackoverflow.com/questions/42757726/… Mar 13, 2017 at 9:45
2

You can use this on your plugin for remove all default route.

remove_action( 'rest_api_init', 'create_initial_rest_routes', 0 );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.