How to Localize the site title and catch phrase with THE THOR WP Theme and the Bogo plugin

This blog have been using the wordpress theme “THE THOR”. The other language version is also created and to localize with plugin “Bogo”. The Bogo has a function to replace text but the site title and the catch phrase couldn’t replace, so they had been exported in Japanese because the main language of this blog is Japanese. I want to replace them too so I had edit the functions.php of the child theme. At last, the site title and the catch phrase now to be localized.

This article explains that how to do it.

The way in this article, edit the file of the child theme. Please backup the file before edit them.
スポンサーリンク

Generating the site title string

THE THOR implements the hook function of the pre_get_document_title to generate the site title string. I found the fit_title_document() function in the the-thor/inc/seo/title.php file.

Override this function.

Override the hook function in the child theme

It is dangerous that you edit the file in the parent theme, so implement the hook function in the child theme.

Edit the the-thor-child/functions.php file.

Generating the site title tag string

Add the following code into the the-thor-child/functions.php file.

function localize_title() {
	ob_start();
	bloginfo('name');
	$localizedName = ob_get_clean();
	
	ob_start();
	bloginfo('description');
	$localizedDescription = ob_get_clean();
	
	$originalName = get_bloginfo('name');
	$originalDescription = get_bloginfo('description');
	
	$title = fit_title_document();
	$title = str_replace($originalName, $localizedName, $title);
	$title = str_replace($originalDescription, $localizedDescription, $title);
	
	return $title;
}

This code execute following steps:

  1. Get the localized title
  2. Get the localized catch phrase
  3. Get the original title
  4. Get the original catch phrase
  5. Generate the string which is exported into the title tag
  6. Replace the title string in the generated string with the localized title
  7. Replace the catch phrase string in the generated string with the localized catch phrase
  8. Return new string

I referred to the following article when I wrote above code.

東京のWeb制作会社LIG

LIGのフロントエンドエンジニア・つっちーが、WordPressの多言語化プラグイン「Bogo」の機能を使った、サイトの…

Replace the hook function

Replace the hook function to make the localize_title() function to be called.

Add the following code into the the-thor-child/functions.php file.

function set_after_parent_theme() {
	remove_action('pre_get_document_title', 'fit_title_document');
	add_filter('pre_get_document_title', 'localize_title');
}
add_action('after_setup_theme', 'set_after_parent_theme', 20);

Now, the implemented hook function to be called, the localized title and the catch phrase are used.

About THE THOR and Bogo

“THE THOR” is a wordpress theme, which is 

“THE THOR” is a paid WordPress theme. This is a high-performance theme that supports the latest coding and AMP with HTML5 + CSS3.

For the detail, see public site:

集客・収益にこだわったWordPressテーマ「THE THOR(ザ・トール)」

The “Bogo” is a wordpress plugin to localize the site. It is not a translator, you need to create the localized article by hand. If you simply create localized pages, the Google doesn’t recognize them as a localized version. They may be recognized as a duplicated contents. The “Bogo” create the appropriated meta tag to notify the localized pages.

For the detail about “Bogo”, see following page:

Bogo – WordPress プラグイン | WordPress.org 日本語

スポンサーリンク
最新情報をチェックしよう!
>現役のプログラマーが書くプログラミング情報

現役のプログラマーが書くプログラミング情報

日々の開発の中での学びや分かったこと、調べたことなどを書いていくブログです。

CTR IMG