
One of the Essential Tasks When Running Multiple Language Sites Across Multiple Domains
花<br>HANAWhen I asked Gemini to generate the code, it included unnecessary comments in the code.
Example) “SEO Basics” etc. The following is correct, but please be careful even with Gemini Pro (Summer 2026).
If you show a screenshot of your screen to the AI, it will create something tailored to your site.
💻 Summary of Task Outline, Purpose, and SEO Effects
| Item | Content |
|---|---|
| Task Outline | Automated insertion of hreflang tags (language alternate tags) into the <head> section using functions.php. |
| Primary Purpose | Explicitly signaling the paired relationship between the English site (parent) and the Japanese site (child) sharing identical content to search engines. |
| SEO Effects | • Avoid penalty risks caused by duplicate content issues. • Accurately display the appropriate language page (English/Japanese) in search results based on the user’s language settings. • Prevent the dilution of page authority for each language and optimize search engine indexing. |
💻 Purpose and Overview of the Task
To ensure Google correctly recognizes your pages as distinct languages, the tag pointing from “A (English) to B (Japanese)” and the tag pointing from “B (Japanese) to A (English)” must be set up as a pair (bi-directional).
If the tag exists on only one of the sites, Google will treat it as an error and invalidate it.
Therefore, you must paste the exact same code into the respective functions.php files of both domains (on both WordPress installations).
💻 Code to Paste into functions.php for Universal Automation of hreflang (Multilingual) Tags
function add_custom_hreflang_tags() {
if ( is_404() || is_search() ) {
return;
}
$parsed_url = wp_parse_url( $_SERVER['REQUEST_URI'] );
$path = isset( $parsed_url['path'] ) ? $parsed_url['path'] : '/';
$en_url = 'https://example.com' . $path;
$ja_url = 'https://jp.example.com' . $path;
echo '<link rel="alternate" hreflang="en" href="' . esc_url($en_url) . '" />' . "\n";
echo '<link rel="alternate" hreflang="ja" href="' . esc_url($ja_url) . '" />' . "\n";
echo '<link rel="alternate" hreflang="x-default" href="' . esc_url($en_url) . '" />' . "\n";
}
add_action(‘wp_head’, ‘add_custom_hreflang_tags’);
Why Bi-directional hreflang Tags Matter
To ensure Google recognizes your multilingual content correctly, hreflang tags must be bi-directional. The English page must link to the Japanese page, and the Japanese page must link back to the English page. One-way tagging triggers validation errors and gets ignored by search engines.
Key Benefits
- Zero Duplicate Penalties: Eliminates search engine penalties for identical content across regions.
- Accurate Targeting: Automatically serves the correct language version based on user location and settings.
- Link Equity Retention: Consolidates ranking signals and authority across all language variants.
7-Step Implementation Guide for SWELL Theme (WordPress)
Instead of manual tagging, you can automate this across both domains by injecting a dynamic program into functions.php.
- Activate Child Theme: Go to Appearance > Themes and ensure
SWELL CHILDis active. Never edit the parent theme directly. - Open Code Editor: Navigate to Appearance > Theme File Editor.
- Select SWELL Child: Choose
SWELL CHILDfrom the dropdown in the top-right corner and click Select. - Open Functions File: Click
functions.phpfrom the file list on the right. - Insert Code: Paste your automated PHP script at the very bottom of the editor.
- Save: Click Update File and ensure the success message appears.
- Verify: Visit any live post, view the page source (
Ctrl+UorCmd+Option+U), and verify that the threehreflangtags are active in the<head>section.


