Making a WordPress theme translation ready means anyone can easily change its text to another language. This helps your website reach more people worldwide.
You want your website visitors to see content in their own language.
You plan to share your theme with users from different countries.
You want to prepare your theme for easy translation by others.
You want to support multilingual plugins like WPML or Polylang.
You want to follow WordPress best practices for themes.
Syntax
Wordpress
__('Text to translate', 'text-domain');
_e('Text to translate', 'text-domain');
load_theme_textdomain('text-domain', get_template_directory() . '/languages');
__() returns the translated text.
_e() echoes (prints) the translated text directly.
Examples
This returns the translated version of 'Hello, world!' using the 'mytheme' text domain.
Wordpress
echo __('Hello, world!', 'mytheme');
This prints the translated 'Welcome to my site' text directly.
Wordpress
_e('Welcome to my site', 'mytheme');
This loads the translation files from the 'languages' folder inside your theme.
Wordpress
function mytheme_setup() {
load_theme_textdomain('mytheme', get_template_directory() . '/languages');
}
add_action('after_setup_theme', 'mytheme_setup');
Sample Program
This example shows how to load translation files and print a translated greeting in your theme.
Wordpress
<?php
function mytheme_setup() {
load_theme_textdomain('mytheme', get_template_directory() . '/languages');
}
add_action('after_setup_theme', 'mytheme_setup');
// In a template file
_e('Hello, visitor!', 'mytheme');
?>
OutputSuccess
Important Notes
Always use a unique text-domain matching your theme folder name.
Place your translation files (.mo and .po) inside the /languages folder.
Use tools like Poedit or Loco Translate plugin to create translation files.
Summary
Make your theme text translatable using __() and _e().
Load your theme's text domain with load_theme_textdomain() in after_setup_theme hook.
Store translation files in a /languages folder inside your theme.
Practice
(1/5)
1. Which function is used to make a string translatable in a WordPress theme without immediately displaying it?
easy
A. translate_text()
B. _e()
C. load_theme_textdomain()
D. __()
Solution
Step 1: Understand translation functions
__() returns the translated string without printing it, while _e() echoes it immediately.
Step 2: Identify the function that returns the string
Since the question asks for making a string translatable without displaying it, __() is the correct choice.
Final Answer:
__() -> Option D
Quick Check:
Return translatable string = __() [OK]
Hint: Use __() to get translated text without printing [OK]
A. Using 'init' hook instead of 'after_setup_theme' for loading text domain
B. Missing text domain parameter in __('Hello World')
C. Incorrect path to languages folder
D. Using echo instead of _e() for translation
Solution
Step 1: Check hook used for loading text domain
The code uses 'init' hook, which is too late for loading theme translations properly.
Step 2: Identify recommended hook
The recommended hook is 'after_setup_theme' to ensure translations load early in theme setup.
Final Answer:
Using 'init' hook instead of 'after_setup_theme' for loading text domain -> Option A
Quick Check:
Load text domain on after_setup_theme, not init [OK]
Hint: Load text domain on after_setup_theme hook, not init [OK]
Common Mistakes:
Using init hook for load_theme_textdomain
Forgetting to add text domain in translation functions
Confusing echo and _e() usage
5. You want to make your WordPress theme fully translation-ready. Which combination of steps is correct?
A) Wrap all user-facing strings with _e() or __(), load text domain in after_setup_theme, and place translation files in /languages folder.
B) Use _e() only, load text domain in init hook, and place translation files in theme root.
C) Wrap strings with __(), load text domain in wp_loaded hook, and place translation files in /lang folder.
D) Use _e() and __() without loading text domain, place translation files anywhere.
hard
A. Wrap strings with __(), load text domain on wp_loaded, store files in /lang
B. Use _e() only, load text domain on init, store files in theme root
C. Wrap strings with _e() or __(), load text domain on after_setup_theme, store files in /languages
D. Use _e() and __() without loading text domain, store files anywhere
Solution
Step 1: Identify correct translation function usage
Both _e() and __() should be used to wrap user-facing strings for translation.
Step 2: Confirm proper hook and folder for translations
Text domain must be loaded on after_setup_theme hook, and translation files should be stored in a /languages folder inside the theme.
Final Answer:
Wrap strings with _e() or __(), load text domain on after_setup_theme, store files in /languages -> Option C
Quick Check:
Correct functions + hook + folder = Wrap strings with _e() or __(), load text domain on after_setup_theme, store files in /languages [OK]
Hint: Use _e()/__(), after_setup_theme hook, and /languages folder [OK]