0
0
Wordpressframework~5 mins

Theme translation readiness in Wordpress

Choose your learning style9 modes available
Introduction

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.