The WP REST API exposes a lot of information so I filter endpoints that aren't needed to expose.

I can't filter everything: The location of needed media files are exposed for example.

As an extra protection I'd like to mystify the default uri.

I would like to change for example: http://example.com/wp-json/wp/v2/ to http://example.com/mistified/wp/v2/

Is this rather easy possible?

  • For protection? The URL will still be visible in your HEAD which means anyone can see it in your source. And the namespace should automatically show all your available endpoints. See v2.wp-api.org/guide/discovery – jgraup Nov 30 '16 at 12:17
  • Non-api requests will be redirected to an external url where the frontend app lives. So I don't think it will show in the HEAD there. I filtered out all default endpoints including /wp/v2. Only the custom post types are exposed now. And of course the `wp-json' prefix. – violacase Nov 30 '16 at 14:14
  • Did you ever find a solution to this not working @violacase ? – rorymorris89 Jan 19 '17 at 10:26

Please note that for current versions of WordPress, using the json_url_prefix filter no longer works.

On WordPress 4.7 (and using the REST API from the core instead of a plugin), this is what I needed to change the API prefix.

add_filter( 'rest_url_prefix', 'my_theme_api_slug'); 
function my_theme_api_slug( $slug ) { return 'api'; }

If this doesn't work straight away, you'll need to flush the rewrite rules. You can run this piece of code once to do so (don't leave it in your code so it runs everytime):

  • Additionally, you may create a procedure by using php to curl to a certain old endpoint, check to see if that is still working, then that's the time you flush_rewrite_rules(true); but if the curl response says that the api is now working, you no longer need to flush – Abel Melquiades Callejo Mar 19 '20 at 23:33

You could use the json_url_prefix hook to remove 'wp-json' across all API routes. The below example will do the example in your question:

add_filter( 'json_url_prefix', 'my_theme_api_slug'); 
function my_theme_api_slug( $slug ) { 
    return 'mistified';
  • I can't get this to work. Perhaps a reflushing problem? – violacase Dec 1 '16 at 14:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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