API Example: How to redirect to original page on translation engine error
Translator Plugin normally shows an error page when none of the translation engines can translate a page. We had many requests in the past to re-direct to the original page on translation error. Here is how you can do it with the new post content filter hook.
// Translator post filter hook to 302 redirect to original page when there is an error in translation.
function tgTranslatorPostFilterHook($data, $language, $engine, $url, $translationError = false) {
if($translationError) {
// 302 temporary redirect to the original untranslated page for any ‘TRANSLATION ERROR’
@header(”HTTP/1.1 302 Moved Temporarily”);
@header(”Location: ” . $url);
@header(”Status: 302 Moved Temporarily”);
exit();
}
return $data;
}
Insert the above code in any WordPress plugin (or create a new plugin) and activate it. Now on translation error, instead of showing an error page, you will be re-directed to the original page. This way your users at least get to see the original content and search engines are also happy. As the re-direct is through temporary 302 code, the search engines will come back again and again to see if the translated page is available.
Tags: Translator Plugin, WordPress, WordPress Translator, WordPress Translator Plugin Gold, WordPress Translator Plugin Pro