apply_filters( ‘rest_url_prefix’, string $prefix )

Filters the REST URL prefix.

Parameters

$prefixstring
URL prefix. Default 'wp-json'.

Source

return apply_filters( 'rest_url_prefix', 'wp-json' );

Changelog

VersionDescription
4.4.0Introduced.

User Contributed Notes

  1. Skip to note 4 content

    If you want to change WordPress’s default REST API URL prefix from wp-json to another prefix e.g. api add the following code to your theme’s functions.php file or in a custom plugin:

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

    Now, refresh rewrite rules by going to Settings -> Permalinks and hit Save Changes.

    Your new REST API URL will be example.com/api/ instead of the default example.com/wp-json/.

You must log in before being able to contribute a note or feedback.