1

For more context:

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

It seems that it's rather easy to change wp-json to anything.


I'm passing this link to my custom route to the JS file through localization:

$params = [
    'rest_link' => esc_url( get_site_url() . '/wp-json/block_help/v1/block_identification?block_identifier=' )
];
wp_localize_script( $handle, 'block_help_data', $params );

But I wonder, is it correct to also add the /wp-json/ to the hard-coded link as well? Most likely not, but if so -

Isn't there any get_json_prefix function that I can use to retrieve whatever the new prefix is?

| improve this question | | | | |
3

Sure they can!

Actually the structure you used is assuming that url rewrites are on. Which may be or may be not.

To assure the right endpoint, you must use get_rest_url function: https://developer.wordpress.org/reference/functions/get_rest_url/

So in your case, this would be:

'get_rest_url' => get_rest_url(null, '/block_help/v1/block_identi...')
| improve this answer | | | | |

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.