mbis

TranslatePress compatiblity hook

Dec 23rd, 2020 (edited)
778
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.48 KB | None | 0 0
  1. function pm_prepend_lang_prefix($base, $element) {
  2.     global $TRP_LANGUAGE;
  3.    
  4.     if(!empty($TRP_LANGUAGE)) {
  5.         $trp = TRP_Translate_Press::get_trp_instance();
  6.         $trp_url_converter = $trp->get_component('url_converter');
  7.        
  8.         $trp_lang_code = $trp_url_converter->get_url_slug($TRP_LANGUAGE);
  9.         $base = preg_replace("/(.*)(\/{$trp_lang_code})$/", "$1/{$trp_lang_code}", $base);
  10.     }
  11.    
  12.     return $base;
  13. }
  14. add_filter('permalink_manager_filter_permalink_base', 'pm_prepend_lang_prefix', 9, 2);
Add Comment
Please, Sign In to add comment