WP REST API Is it rather easy to rename the default wp-json uri part?

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?

2 s
2

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):

flush_rewrite_rules(true);

Leave a Comment