Just for completion, that piece of code was not actually working for me, so I modified it with a hard-coded rule that if the pattern in the URL is detected with the given language code, then strip the URL of the language code (e.g. yourdomain.com/ro/my-page is stripped to yourdomain.com/my-page).
However, this means that the user is shifted back to the original language and when they move onto another page that does provide translation, they need to use the language switcher again to change the language to the secondary language.
In this code to make it work, make sure to modify row no.36 with the secondary language. If you have more than one secondary languages, then it would be more complicated it won’t work.
<?php
/**
* Plugin Name: TranslatePress - Exclude URLs From Translation
* Plugin URI: none
* Description: A mini plugin for TranslatePress to exclude URL paths from translation
* Version: 1.0
* Author: Carlos De Nirro
* Author URI: none
* License: GPL3
*/
/* Copyright Janos Bakalaros (email : [email protected])
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
// Start writing code after this line!
add_action( 'plugins_loaded', 'trpc_exclude_tp_from_pages', -1 );
function trpc_exclude_tp_from_pages(){
$do_not_translate_path = array('quizzes');
foreach ( $do_not_translate_path as $path ){
if ( !empty($path) && strpos($_SERVER['REQUEST_URI'], untrailingslashit($path)) !== false ){
add_filter( 'trp_allow_tp_to_run', function(){return false; } );
$link = str_replace("cs/", "", $_SERVER['REQUEST_URI']);
$_SERVER['REQUEST_URI'] = $link;
}
}
}
-
This reply was modified 4 years, 6 months ago by Carlos.