Is there a function which can be used to get the themes text-domain?
For example, if i want to provide this code to users without them needing to swap out the text-domain, can this be done, rather than this :
register_sidebar(
array(
'name' => __( 'Widget Area', 'twentynineteen' ),
'id' => 'widget-id',
));
Use something like this so they don't need to change the text-domain to match the theme they are using :
register_sidebar(
array(
'name' => __( 'Widget Area', get_text_domain() ),
'id' => 'widget-id',
));
Is there a function which can be used to get the themes text-domain?
For example, if i want to provide this code to users without them needing to swap out the text-domain, can this be done, rather than this :
register_sidebar(
array(
'name' => __( 'Widget Area', 'twentynineteen' ),
'id' => 'widget-id',
));
Use something like this so they don't need to change the text-domain to match the theme they are using :
register_sidebar(
array(
'name' => __( 'Widget Area', get_text_domain() ),
'id' => 'widget-id',
));
Share
Improve this question
edited Oct 15, 2020 at 10:07
Brad Dalton
asked Oct 15, 2020 at 5:48
Brad DaltonBrad Dalton
6,9652 gold badges36 silver badges47 bronze badges
1 Answer
Reset to default 1No, there isn't. The text domain needs to be hard coded, otherwise it can't be read by localization tools which parse the code without executing it.
See this note from the Internationalization documentation
The text domain should be passed as a string to the localization functions instead of a variable. It allows parsing tools to differentiate between text domains. Example of what not to do:
__( 'Translate me.' , $text_domain );
The string itself also cannot be a variable or function for the same reason.