Skip to content

Instantly share code, notes, and snippets.

@grappler
Created October 20, 2013 12:00
Show Gist options
  • Save grappler/7068629 to your computer and use it in GitHub Desktop.
Save grappler/7068629 to your computer and use it in GitHub Desktop.
Load only one translations file.
<?php
function theme_name_setup(){
$domain = 'theme-name';
if ( $loaded = load_theme_textdomain( $domain, trailingslashit( WP_LANG_DIR ) . $domain ) ) {
return $loaded;
} elseif ( $loaded = load_theme_textdomain( $domain, get_stylesheet_directory() . '/languages' ) {
return $loaded;
} else {
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 );
if ( $loaded = load_textdomain( $domain, trailingslashit( WP_LANG_DIR ) . $domain . '/' . $domain . '-' . $locale . '.mo' ) ) {
return $loaded;
} else {
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