Make a custom theme translate-ready

To do it properly, you need to generate a valid .mo file and load the text domain in your theme functions.php:

function wpse222346_localize_theme() {

    load_theme_textdomain( 'your_theme_domain', get_template_directory() . '/languages' );

}

add_action( 'after_setup_theme', 'wpse222346_localize_theme' );

You can check the WordPress Codex for more info on the load_theme_textdomain function: https://codex.wordpress.org/Function_Reference/load_theme_textdomain

Then you would call the translatable strings using your theme’s text domain:

<h2><?php _e( 'know_more', 'your_theme_domain' ); ?></h2>

Also, it’s strongly advised to use a tool for automating the creation of the POT files. It makes maintainability much easier. There are many options, such as Poedit, several online generators, makepot.php and even a very nice plugin to do it from the WordPress Dashboard called LocoTranslate. Most of them will also help you creating the .PO and .MO files.

Leave a Comment