Hello,
You can exclude the path in TranslatePress -> Settings -> Advanced -> Exclude strings -> Do not translate certain paths
It should stop TP from translating and adding the language parameter in a secondary language.
Best Regards
Thread Starter
Iudex
(@iudex)
Thanks for the quick reply. I already tried setting all kinds of variations of the URL that is used for the REST API namespace without any luck. Even the page that calls the REST API. But even if I already added all kinds of variations, shouldn’t /wp-json/* be enough?
Unfortunately neither works. Somehow it seems that it doesn’t apply for API calls. I still get an “Unauthorized” error in the console, with the link to the API with the language code in the URL (/en/wp-json/….).
-
This reply was modified 1 year, 3 months ago by
Iudex.
If you need to access the non /en/ version, simply don’t call it.
Is the plugin that’s trying to access it from your own website? And the error is in the browser console?
Depending on how the plugin is generating the link to the json api, it might or might not be fixable.
Can you please give us a bit more information?
For example, on secondary languages, the home_url get filltered in order to receive the language parameter.
The site_url however does not receive the site URL. So this means you can use site_url to construct a URL without the language parameter.
Thread Starter
Iudex
(@iudex)
The plugin is using the get_rest_url() function, and when TranslatePress is used this URL is returned with a language code and therefore returning a link that doesn’t work.
Thread Starter
Iudex
(@iudex)
The error is displayed in the console, yes. I have checked what get_rest_url() returns and can confirm that TranslatePress adds the language code as the slug in the returned URL. This will make plugins using get_rest_url() unsuable. And I find no way to disable it in TranslatePress. Already tried excluding the API URLs in TranslatePress, but doesn’t seem to work for that function.
Hi,
Can you try out this code to remove the lang param from the rest api?
/*
* Remove language from plugin rest api.
*/
add_filter( ‘trp_home_url’, ‘trp_home_url_no_lang_for_rest_api’, 10, 5);
function trp_home_url_no_lang_for_rest_api( $new_url, $abs_home, $TRP_LANGUAGE, $path, $url ){
if (str_contains($path, ‘wp-json/plugin-name’)){
return $url;
}
return $new_url;
}
Thread Starter
Iudex
(@iudex)
Seems like this is working fine!
Thread Starter
Iudex
(@iudex)
@sareiodata Seems I was a bit too quick in my reply. Not resolved. Same error.
-
This reply was modified 1 year, 1 month ago by
Iudex.