Skip to content

Instantly share code, notes, and snippets.

@glueckpress
Last active December 14, 2015 21:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save glueckpress/e2f400398cd4d0e19e17 to your computer and use it in GitHub Desktop.
Save glueckpress/e2f400398cd4d0e19e17 to your computer and use it in GitHub Desktop.
[WordPress] Parent/child theme l10n logic.
<?php
/**
* child-theme/functions.php
*
* Loads first, before parent-theme/functions.php.
*/
function child_after_setup_theme() {
load_child_theme_textdomain( 'child-textdomain', get_stylesheet_directory() . '/languages' );
}
add_action( 'after_setup_theme', 'child_after_setup_theme' );
// Child theme translation works, because of different textdomain.
function child_string() {
printf( __( 'The URL of the active theme is: %s', 'child-textdomain' ), get_stylesheet_directory_uri() );
}
// Child theme translation **doesn’t** work, because parent_textdomain loads afterwards and overrides child translation.
function child_string() {
printf( __( 'The URL of the active theme is: %s', 'parent-textdomain' ), get_stylesheet_directory_uri() );
}
<?php
/**
* parent-theme/functions.php
*
* Loads after child-theme/functions.php.
*/
function parent_after_setup_theme() {
load_theme_textdomain( 'parent-textdomain', get_template_directory() . '/languages' );
}
add_action( 'after_setup_theme', 'parent_after_setup_theme' );
// Overrides translation for identical string in child_string()
function parent_string() {
printf( __( 'The URL of the active theme is: %s', 'parent-textdomain' ), get_template_directory_uri() );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment