Multilingualize the parts that cannot be multilingualized [Bogo plugin]

An aerial view of a city at night

Bogo is a useful plugin for creating multilingual sites.However, there are a few areas where even Bogo is not multilingual.

We have modified that section to display multiple languages.The following is an explanation of the contents.

This fix could not be handled by functions.php, but by modifying the source files of WordPress itself and the Yoast SEO plugin.If you are going to work on this fix, we recommend you to backup the whole WordPress before you work on it.

Page Language Swicher

Areas not multilingualized in Bogo

Most parts of the site are multilingualized with the Bogo plugin.However, some parts of the original language, Japanese, remain.This time, we will make those parts multilingual.

Specifically,

  • Site Tagline block
  • <title> tag in <head> of the top page
  • Structured data in <head> of the top page (schema.org)

The Japanese-language display will be made multilingual with respect to the following

Site Tagline block

I thought it would be replaced because it is listed in the “Languages” and “Terms Translation” sections of the admin menu, but the text in the Site Tagline block is not automatically replaced even if the locale of the page is changed.However, the text in the “Site Tagline” block is not automatically replaced even if the locale of the page changes.

As a stopgap measure, we did not use the catchphrase block on the site, but instead used the Block Visibility plugin to display what we had typed in normal text according to the language.

In this case, we were able to investigate the cause of the problem and address it by modifying the source files of WordPress itself.

Diff
--- site-tagline.php.orig       2025-02-15 20:55:32.476074037 +0900
+++ site-tagline.php    2025-02-15 15:43:41.950994484 +0900
@@ -15,7 +15,12 @@
  * @return string The render.
  */
 function render_block_core_site_tagline( $attributes ) {
-       $site_tagline = get_bloginfo( 'description' );
+       /* 20250215 get_bloginfo -> bloginfo From */
+       ob_start();
+       bloginfo('description');
+       $site_tagline = ob_get_clean();
+       /* 20250215 get_bloginfo -> bloginfo End */
+       //$site_tagline = get_bloginfo( 'description' );
        if ( ! $site_tagline ) {
                return;
        }
wp-includes/blocks/site-tagline.php

The causes of the site’s catchphrase not being replaced are described in the following pages. (Japanese site)

We will take advantage of this, noting that the bloginfo function handles the post-translation values, while the get_bloginfo function handles the pre-translation values.

If the get_bloginfo function is used to load the site tagline, the original (in this case, Japanese) text is returned, not the multilingualized text.Therefore, the display of the site tagline block was not replaced with the multilingual one.

The above patch replaces the part of site-tagline.php that is read by get_bloginfo(‘description’) with bloginfo(‘description’).Since it cannot be replaced as is, ob_start() and ob_get_clean() are used to receive the string.

By applying this patch, the catchphrase block of the site will be multilingualized.

Note that the site name for this blog is in English in each language, so we did not address this issue this time.It should be possible to deal with it in the same way.

<title> tag and structured data failure

Once the catchphrase block is addressed, the site will be visually multilingual.

However, when I looked at the HTML in the Chrome Developer Tools, there were still some Japanese characters in places.

One is the <title> tag.Japanese was displayed in all languages.

HTML
<title>Clairvoyance Power - ~千里の道も一歩から~</title>
<title> tag

The other is structured data.Some parts of the data were in Japanese in the JSON file.

JSON
"@graph": [
    {
        "@type": "CollectionPage",
        "@id": "https://clairvoyance-power.com/",
        "url": "https://clairvoyance-power.com/",
        "name": "Clairvoyance Power - ~千里の道も一歩から~",
        "isPartOf": {
            "@id": "https://clairvoyance-power.com/#website"
        },
        "about": {
            "@id": "https://clairvoyance-power.com/#/schema/person/fb4fd70540149e2fdea9e6ae8eabab1e"
        },
        "breadcrumb": {
            "@id": "https://clairvoyance-power.com/#breadcrumb"
        },
        "inLanguage": "zh-Hans"
    },
<script type=”application/ld+json” class=”yoast-schema-graph”>
JSON
{
    "@type": "WebSite",
    "@id": "https://clairvoyance-power.com/#website",
    "url": "https://clairvoyance-power.com/",
    "name": "Clairvoyance Power",
    "description": "~千里の道も一歩から~",
    ...snip...
    "inLanguage": "zh-Hans"
},
<script type=”application/ld+json” class=”yoast-schema-graph”>

If you look at line 38, you will see that the language is Simplified Chinese.Normally, we would like to see the catchphrase of the site in Chinese, but Japanese is displayed.

<title> tags and structured data addressed

These parts are output by the Yoast SEO plugin.The aforementioned page describes how to deal with the Yoast SEO plugin, but that content did not replace the structured data part with multi-language.

This time, we will modify the source file of the Yoast SEO plugin to accommodate this: there are three locations; we modify it to use bloginfo() instead of get_bloginfo(); and we modify it to use the bloginfo() method instead of get_bloginfo().

Diff
--- class-wpseo-replace-vars.php.orig   2025-02-15 20:41:57.707080317 +0900
+++ class-wpseo-replace-vars.php        2025-02-15 20:27:59.292149230 +0900
@@ -495,8 +495,13 @@
                static $replacement;

                if ( ! isset( $replacement ) ) {
+                       /* 20250215 get_bloginfo -> bloginfo */
+                       ob_start();
+                       bloginfo('description');
+                       $desc = ob_get_clean();
                        $description = wp_strip_all_tags( $desc );
-                       $description = wp_strip_all_tags( get_bloginfo( 'description' ) );
+                       //$description = wp_strip_all_tags( get_bloginfo( 'description' ) );
+                       /* 20250215 get_bloginfo -> bloginfo */
                        if ( $description !== '' ) {
                                $replacement = $description;
                        }
wp-content/plugins/wordpress-seo/inc/class-wpseo-replace-vars.php
Diff
--- website.php.orig    2025-02-15 20:47:52.567204942 +0900
+++ website.php 2025-02-15 20:26:47.784325248 +0900
@@ -24,13 +24,19 @@
         * @return array Website data blob.
         */
        public function generate() {
+               /* 20250215 get_bloginfo -> bloginfo */
+               ob_start();
+               bloginfo('description');
+               $desc = ob_get_clean();
                $data = [
                        '@type'       => 'WebSite',
                        '@id'         => $this->context->site_url . Schema_IDs::WEBSITE_HASH,
                        'url'         => $this->context->site_url,
                        'name'        => $this->helpers->schema->html->smart_strip_tags( $this->context->site_name ),
-                       'description' => \get_bloginfo( 'description' ),
+                       'description' => $desc,
+               //      'description' => \get_bloginfo( 'description' ),
                ];
+               /* 20250215 get_bloginfo -> bloginfo */

                if ( $this->context->site_represents_reference ) {
                        $data['publisher'] = $this->context->site_represents_reference;
wp-content/plugins/wordpress-seo/src/generators/schema/website.php
Diff
--- rss-footer-embed.php.orig   2025-02-15 20:52:54.467462231 +0900
+++ rss-footer-embed.php        2025-02-15 20:16:14.979891023 +0900
@@ -165,11 +165,17 @@
                        $author_link = \sprintf( $link_template, \esc_url( \get_author_posts_url( $post->post_author ) ), \esc_html( \get_the_author() ) );
                }

+               /* 20250215 get_bloginfo -> bloginfo */
+               ob_start();
+               bloginfo('description');
+               $desc = ob_get_clean();
+
                return [
                        '%%AUTHORLINK%%'   => $author_link,
                        '%%POSTLINK%%'     => \sprintf( $link_template, \esc_url( \get_permalink() ), \esc_html( \get_the_title() ) ),
                        '%%BLOGLINK%%'     => \sprintf( $link_template, \esc_url( \get_bloginfo( 'url' ) ), \esc_html( \get_bloginfo( 'name' ) ) ),
-                       '%%BLOGDESCLINK%%' => \sprintf( $link_template, \esc_url( \get_bloginfo( 'url' ) ), \esc_html( \get_bloginfo( 'name' ) ) . ' - ' . \esc_html( \get_bloginfo( 'description' ) ) ),
+               //      '%%BLOGDESCLINK%%' => \sprintf( $link_template, \esc_url( \get_bloginfo( 'url' ) ), \esc_html( \get_bloginfo( 'name' ) ) . ' - ' . \esc_html( \get_bloginfo( 'description' ) ) ),
+                       '%%BLOGDESCLINK%%' => \sprintf( $link_template, \esc_url( \get_bloginfo( 'url' ) ), \esc_html( \get_bloginfo( 'name' ) ) . ' - ' . \esc_html( $desc ) ),
                ];
        }
wp-content/plugins/wordpress-seo/src/integrations/front-end/rss-footer-embed.php

<title> tag and structured data coping results

By modifying the Yoast SEO source files, the <title> tag and the structured data section are now multilingual.

HTML
<title>Clairvoyance Power - 千里之行,始于足下 -</title>
<title> tag
JSON
"@graph": [
    {
        "@type": "CollectionPage",
        "@id": "https://clairvoyance-power.com/",
        "url": "https://clairvoyance-power.com/",
        "name": "Clairvoyance Power - 千里之行,始于足下 -",
        "isPartOf": {
            "@id": "https://clairvoyance-power.com/#website"
        },
        "about": {
            "@id": "https://clairvoyance-power.com/#/schema/person/fb4fd70540149e2fdea9e6ae8eabab1e"
        },
        "breadcrumb": {
            "@id": "https://clairvoyance-power.com/#breadcrumb"
        },
        "inLanguage": "zh-Hans"
    },
<script type=”application/ld+json” class=”yoast-schema-graph”>
JSON
{
    "@type": "WebSite",
    "@id": "https://clairvoyance-power.com/#website",
    "url": "https://clairvoyance-power.com/",
    "name": "Clairvoyance Power",
    "description": "- 千里之行,始于足下 -",
    ...snip...
    "inLanguage": "zh-Hans"
},
<script type=”application/ld+json” class=”yoast-schema-graph”>

For Simplified Chinese, the catchphrase of the site in that language is displayed.

Musubi

In this article, we have multilingualized the parts of the site that are not multilingualized even with the Bogo plugin.

  • Site Tagline block
  • <title> tag in <head> of the top page
  • Structured data in <head> of top page (schema.org)

Individual post pages were multilingualized, so no action is required.

The site name is also not reflected if the site is multilingualized.This should be handled in the same way as in this case.

I was able to solve a question that I have had since starting this site and working on making it multilingual.However, the source file modifications will be reverted in the update.

In the future, I will look for another way to handle this.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *