I had set up my old site, fodina.de bilingual. With the help of WP-Globus. As nice as this worked for years, at last WP-Globus got lost. Thoroughly! When I edited the German text, it made the English disappear. And vice versa. Something like that shall not happen to me again. The restoration was complex and complicated. So, while migrating to bootScore, I switched to two separate sites.
karsten-reincke.de is a German language site, fodina.de an English. Now there’s no need anymore to translate all contributions alternately. Makes no sense with those, which address only German-speaking readers. Besides this opens thematic free spaces: fodina.de is about FOSS, karsten-reincke.de about my other life.
However, the pages of my pairs shall still refer to each other. So I need an independent easily to insert language ‘switcher’. In other words: a shortcode. Maybe you will also need such a thing sometimes
Solution
- Add the following code to
functions.php
of your child theme:
/*
* (c) 2023 Karsten Reincke
* SPDX-License-Identifier: MIT
*/
function switch_fromto($atts){
$toSite="http://woimmer.de/mywp.toLang";
$atts = (array) $atts;
$fromLang=$atts[0];
$toLang=$atts[1];
$toPage=$atts[2];
$lsw= '<div class="text-right">[ ' . $fromLang . ' | <a href="'
.$toSite . "/". $toPage . '">'. $toLang . '</a> ]</div>';
$res=
'<div class="container">' .
'<div class="d-flex justify-content-end sample-row">' .
'<div class="col-xs">' .
$lsw .
'</div></div></div>';
return $res;
}
add_shortcode('fromto', 'switch_fromto');
- Adjust woimmer.de/mywp.toLang to your reality.
- Add
on the German page of the pair and[ de | en ]
on Englisch.[ en | de ]
Background
Plugins for multilingual sites actually always work the same way. Pages and posts exist internally in two versions. WP-Globus put all variants into the same database entry, separated with markers {:de}...{:}{:en}...{:}
. The rest is optical sugar that the plugin puts over it. That’s why these plugins can and must also include a language changer that is geared to their own kind, which the site administrator can have integrated into the menu.
If the multi-language plugin gets lost, however, you are in trouble. After all, access to the individual language sections is only possible via the plugin itself anyway. Therefore, the safe option is to work with two separate sites. The overhead of maintenance outweighs reliability.