How to customize the multilingual plugin ” Bogo “

2021年1月25日

I used Bogo to support my portfolio site in multiple languages. The customization code required at that time is introduced below.

Support custom posts

By default, it does not support custom posts, so write the following code in function.php.

function my_localizable_post_types( $localizable ) {
	$custom_post_types = array('works-web','works-graphic'); // your custom post name
    return array_merge($localizable,$custom_post_types);
}
add_filter( 'bogo_localizable_post_types', 'my_localizable_post_types', 10, 1 );

If you want to support all post types, write the following code.

function my_localizable_post_types( $localizable ) {
	$args = array(
        'public'   => true,
        '_builtin' => false
	);
	$custom_post_types = array_values(get_post_types( $args ,'names','and'));
    return array_merge($localizable,$custom_post_types);
}
add_filter( 'bogo_localizable_post_types', 'my_localizable_post_types', 10, 1 );

I referred to the following article, but I got an error in the version I’m using (December 2020), so I rewrote it to work for the time being.

WordPress Bogo をカスタム投稿タイプでも使う

BOGO ver3.3更新時に不具合

Limit the custom posts retrieved by get_posts to the language of your choice

This forum explains how to do it. I was also saved because I was actually getting custom posts with get_posts. All you have to do is add one line of parameters. I’m happy.

$posts = get_posts(array(
  //parameters
   'suppress_filters' => false // add this one
));

Customize the shortcode of language switch button

See the article below for details.

wordpressのbogoプラグインのショートコードをカスタマイズする

Show / hide the national flag

If you want to hide the national flag, write the following code in function.php.

add_filter( 'bogo_use_flags','bogo_use_flags_false');
function bogo_use_flags_false(){
 return false;
}

Rewriting language name

I wanted to change “Japanese | English” to “JP | EN”, so I forcibly rewrite it.

add_filter( 'bogo_language_switcher','replace_bogo_text');
function replace_bogo_text($output){
		$output = str_replace('English','EN',$output);
		$output = str_replace('日本語','JP',$output);
		return $output;
}

If you want to do it properly instead of forcing it, it seems that you can copy the code from the plugin and overwrite the short code (or newly register with a different name).

言語スイッチャーのスタイルを変更する

Change elements for each language in the template

<?php $locale = get_locale();
if ('en_US' == $locale  ) { ?>
<!--English-->
<?php } else { ?>
<!--Japanese -->
<?php } ?>

テンプレート内で言語ごとに表示を変える

Error when server is up

This is what I actually experienced, but I got an error when I uploaded the data to the server under the following conditions.

1.Introduce Bogo locally

2.Export the local site with the plugin “All-in-One WP Migration”

3.Import the site using the plug-in “All-in-One WP Migration” → An error occurs that the English page becomes a 404 error

This is a mystery, but when I imported it into a newly created WordPress site, it worked. So I introduced it of creating a new database of the site and importing it again. Perhaps the database overwrite wasn’t working somewhere. It is dangerous to install it on an operating site, so it is a good idea to make a backup and test it once.

That’s all.

Below is an article comparing Bogo with other plugins.

WordPress : 多言語プラグインの比較 2020年最新