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',
));
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
No, 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.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0