Polylang: Translate Theme Labels on English Pages Only (Cocoon)

Advertisement
Polylang and Cocoon: translate theme labels on English pages only Blogging
Advertisement

After I added English versions of my posts with Polylang, the article text, menus and widgets were all in English. A few labels from the theme were not. The table of contents still said 目次, the share box said シェアする, and the related posts heading said 関連記事. To an English reader, the page suddenly switched to Japanese in all the places they look first.

The short answer: those labels are values saved in the theme settings, so Polylang can’t translate them. A small snippet that swaps the saved values only while an English page is being displayed fixes it. The Japanese pages and the settings screen stay unchanged.

Table of contents on the Japanese page and on the English page. The English page says Contents
The same post in Japanese (left) and English (right). The table of contents heading now reads “Contents”.

My setup in November 2026: the Cocoon theme for WordPress (a popular free Japanese theme, used via its child theme), Polylang 3.9.2 (free) and Code Snippets. The idea works with any theme that keeps its labels in Customizer-style settings; only the setting names change.

Why some labels ignore the page language

Buttons on the English pages had already switched by themselves. The “コピー” share button turned into “Copy” for example. Those come from the theme’s translation files, which follow the page language that Polylang sets.

The labels that stayed in Japanese were the ones you can type into a box on the theme’s settings screen. Whatever you type there is saved once in the database, shared by every language. Change it to English in the settings, and the Japanese pages switch to English too.

Polylang’s Strings translations screen doesn’t help either: it only lists strings that a theme or plugin registers for translation. Cocoon doesn’t register these settings.

Step 1: swap the labels on English pages only

WordPress stores a theme’s settings in one database option named theme_mods_ followed by the theme’s folder name. WordPress lets you filter an option every time it’s read. The snippet below hooks that read, checks the current Polylang language, then replaces the values only for English pages.

  1. Install the Code Snippets plugin (pasting into your child theme’s functions.php works too).
  2. Go to Snippets → Add New, paste the code below.
  3. Leave it set to run everywhere, then save and activate it.
// Show Cocoon labels in English on English pages only (saved settings stay unchanged)
add_filter( 'option_theme_mods_cocoon-child', function ( $mods ) {
	if ( is_admin() || wp_doing_ajax() || ( defined( 'REST_REQUEST' ) && REST_REQUEST ) ) { return $mods; }
	if ( ! is_array( $mods ) || ! function_exists( 'pll_current_language' ) || pll_current_language() !== 'en' ) { return $mods; }
	$en = array(
		'ad_label_caption'         => 'Advertisement',
		'related_entry_heading'    => 'Related Posts',
		'toc_title'                => 'Contents',
		'toc_open_caption'         => 'Show',
		'toc_close_caption'        => 'Hide',
		'sns_bottom_share_message' => 'Share',
		'sns_follow_message'       => 'Follow #{author}',
		'comment_heading'          => 'Comments',
		'comment_form_heading'     => 'Leave a Comment',
		'comment_submit_label'     => 'Post Comment',
		'404_page_message'         => 'Sorry, the page you were looking for was not found.',
		'pr_label_large_caption'   => 'This article contains ads.',
	);
	foreach ( $en as $k => $v ) {
		if ( isset( $mods[ $k ] ) ) { $mods[ $k ] = $v; }
	}
	return $mods;
} );

This is the exact code running on this site right now. Feel free to use it. The first check skips admin screens, the REST API, and ajax calls. That matters: if the settings screen showed the English values, saving it once would overwrite your original labels. To undo everything, deactivate the snippet.

What to change for your site

Where What to put there
cocoon-child on line 2 Your active theme’s folder name. The official Cocoon child theme zip installs as cocoon-child-master.
'en' on line 4 The code of your English language in Languages → Languages
The right side of lines 6–17 The English text you want. Delete lines you don’t need.
#{author} Keep it. Cocoon replaces it with the author name.
The setting names on the left For another theme, use its own setting names. You can see them as the name of each field when you inspect its settings screen in your browser.

Here are the twelve Cocoon settings this replaces.

Setting Japanese (my settings) English pages
toc_title / toc_open_caption / toc_close_caption 目次 / 開く / 閉じる Contents / Show / Hide
sns_bottom_share_message シェアする Share
sns_follow_message #{author}をフォローする Follow #{author}
related_entry_heading 関連記事 Related Posts
ad_label_caption スポンサーリンク Advertisement
comment_heading / comment_form_heading / comment_submit_label コメント / コメントをどうぞ / コメントを送信 Comments / Leave a Comment / Post Comment
404_page_message お探しのページは見つかりませんでした。 Sorry, the page you were looking for was not found.
pr_label_large_caption 記事内に広告が含まれています。 This article contains ads.
Headings under a post on both pages. The English page shows Share, Follow hamutetu, Related Posts
Under each post, the share box, the follow box and the related posts heading are in English now. Buttons like “Copy” had already switched.

Step 2: give English pages their own menus

Menus need no code. Polylang adds a menu location per language.

  1. In Appearance → Menus, create a new menu for English. Mine has Contact and Sitemap in the header; the footer adds a Privacy Policy link.
  2. Add the English versions of your pages (the /en/ ones) as menu items.
  3. Under Menu Settings → Display location, tick the location with the language name (for example “Header Menu English”), then save.

The Japanese locations keep their existing menus, so nothing changes on the Japanese side.

Step 3: check both languages

Open the same post in both languages. Compare the table of contents, the share box, the follow box, the related posts heading, and the comment form. If you use a caching plugin, clear the cache first. On my site, no Japanese was left on the English pages, while the Japanese pages looked exactly the same as before.

Things to watch

  • Don’t fix it in the theme settings. Those values are shared by all languages, which is the whole problem.
  • Only swap on the front end. Without the admin check, saving the settings screen could write the English text into the database.
  • Skins can win. In Cocoon, a value fixed by a skin takes priority over the saved setting (see get_theme_option in the Cocoon source). If one label won’t change, check your skin.

Wrapping up

If theme labels stay in your main language on Polylang’s English pages, they’re probably saved settings. Leave the settings alone. Swap the values only while English pages render, then assign English menus to Polylang’s per-language locations. The English pages become fully English, while the original pages stay untouched.

References

Comments

Copied title and URL