Last active
December 14, 2015 21:39
-
-
Save glueckpress/e2f400398cd4d0e19e17 to your computer and use it in GitHub Desktop.
[WordPress] Parent/child theme l10n logic.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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() ); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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