Whenever I like a plugin, I usually check out other plugins that are made by the same developer.
From that, I found a hidden gem called Bogo, a multilingual plugin made by Contact Form 7‘s developer.
How it Works
Instead of using custom database tables (like other competing plugins), it duplicates the Page and assigns the same URL slug. It’s normally not allowed by WordPress, but the plugin overrides that restriction.
Then visitors can choose the language by clicking the switcher created by the shortcode [bogo]
.
Now your site will serve the post with the chosen language. Additionally, your Blog Index page will only list translated posts.
Setup Process
- Download and install Bogo. Go to the new “Languages” tab and choose the supported languages.
- Edit an existing post or page. You will find a new section in the sidebar to add a translation. Click the button to duplicate the post or page.
- Lastly, edit the duplicated post or page and manually translate the text. Do not change the URL slug since it can break the language switcher.
Dropdown Language Switcher
There is no filter or action that allow us to edit the markup. So we need to create our own.
In the example below, we will create a shortcode named [bogo-dropdown]
. You need to replace the [bogo]
shortcode with this.
add_shortcode( 'bogo-dropdown', 'my_bogo_shortcode' );
function my_bogo_shortcode( $atts ) {
if( !function_exists( 'bogo_language_switcher_links' ) ) { return; }
$links = bogo_language_switcher_links( $args );
$count = 0;
$output = "<select onchange='this.options[this.selectedIndex].value && (window.location = this.options[this.selectedIndex].value);' >";
foreach( $links as $link ) {
// abort if empty href
if(empty( $link['href'] )) { continue; }
$extra = '';
if ( get_locale() === $link['locale'] ) {
$extra = 'selected disabled';
}
$output .= "<option value='{$link['href']}' {$extra}> {$link['title']} </option>";
$count++;
}
$output .= "</select>";
// if only 1 language, output nothing
if( $count <= 1 ) {
return '';
}
return $output;
}
Conclusion
Bogo has been my go-to multilingual plugin for years. It is solid, reliable and conflict-free.
It doesn’t try to do fancy stuff like creating a custom Database table. Everything is just a plain post and URL rewrite.
Even if you deactivate the plugin, your translated posts and pages are still there. Although it’s not visible via front-end.
Feel free to ask any question regarding Bogo in the comment below 🙂
thanks for the description of Bogo. i was just wondering if its possible to show the languages in a dropdown menu on the page (as many countries have more than two languages)? It doesn't look nice having 6 languages in a big box at the front page...
Hi Lea,
Yes it's possible. I have put a code snippet above on how to do it.
Thank you for this excellent article. Bogo is indeed a great plugin. But would you know the procedure to translate the site's menu? Many thanks
Thanks for reading @joportalis!
I haven't done that before, but it should be possible by using ACF to add a custom field like "title_es_MX" to the Menu Item. Then use filter
wp_nav_menu_objects
to check for what language it is currently active and replace the title.You can check the language using the global $post object.
Hello! nice article. I do have a question: for the lang switcher shortcode how can flags be displayed instead of text as links? Also what have you been using to translate static code which is not supported currently in bogo it seems? Have a nice weekend!
Hi, the default [bogo] shortcode already have the flags. If you want to hide the text, simply use CSS to set display none.
Static code can be translated this way https://codex.wordpress.org/I18n_for_WordPress_Developers
Enclose a string like this
__( 'Hello World' )
and use program like POEdit to translate it. It can auto detect those string.Thank you but doing so doesn't convert flags into links it seems. Also i realized static content can be easily translated by specifying a different page template for each language page.
Very informative article.