Skip to content

Instantly share code, notes, and snippets.

@marcelotorres
Forked from grappler/functions.php
Created November 26, 2016 14:47
Show Gist options
  • Save marcelotorres/1048a48783fded02924e273f617851a0 to your computer and use it in GitHub Desktop.
Save marcelotorres/1048a48783fded02924e273f617851a0 to your computer and use it in GitHub Desktop.
Loading theme and plugin translations in WordPress - https://ulrich.pogson.ch/load-theme-plugin-translations
<?php
function theme_name_setup(){
$domain = 'theme-name';
// wp-content/languages/theme-name/de_DE.mo
load_theme_textdomain( $domain, trailingslashit( WP_LANG_DIR ) . $domain );
// wp-content/themes/child-theme-name/languages/de_DE.mo
load_theme_textdomain( $domain, get_stylesheet_directory() . '/languages' );
// wp-content/themes/theme-name/languages/de_DE.mo
load_theme_textdomain( $domain, get_template_directory() . '/languages' );
}
add_action( 'after_setup_theme', 'theme_name_setup' );
<?php
function plugin_name_load_plugin_textdomain() {
$domain = 'plugin-name';
$locale = apply_filters( 'plugin_locale', get_locale(), $domain );
// wp-content/languages/plugin-name/plugin-name-de_DE.mo
load_textdomain( $domain, trailingslashit( WP_LANG_DIR ) . $domain . '/' . $domain . '-' . $locale . '.mo' );
// wp-content/plugins/plugin-name/languages/plugin-name-de_DE.mo
load_plugin_textdomain( $domain, FALSE, basename( dirname( __FILE__ ) ) . '/languages/' );
}
add_action( 'init', 'plugin_name_load_plugin_textdomain' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment