gettext
最后更新于:2021-11-26 10:40:04
apply_filters( ‘gettext’, string $translation, string $text, string $domain )
Filters text with its translation.
参数
- $translation
-
(string)
Translated text. - $text
-
(string)
Text to translate. - $domain
-
(string)
Text domain. Unique identifier for retrieving translated strings.
源文件
文件: gc-includes/l10n.php
add_action( 'login_head', 'default_login_page_head' ); /** * Customise the login form using login_head. */ function default_login_page_head() { add_filter( 'gettext', 'change_login_form_register_keyword'); } /** * Change Register text from the bottom of login form. * * @param $text string * @return $text string * * * * * * * * * * * * * * * * * * */ function change_login_form_register_keyword( $text ) { $text = str_ireplace( 'Register', 'Sign Up', $text ); return $text; }
add_filter( 'gettext', 'theme_change_comment_field_names', 20, 3 ); /** * Change comment form default field names. * * @link https://codex.gechiui.org/Plugin_API/Filter_Reference/gettext */ function theme_change_comment_field_names( $translated_text, $text, $domain ) { if ( is_singular() ) { switch ( $translated_text ) { case 'Name' : $translated_text = __( 'First Name', 'theme_text_domain' ); break; case 'Email' : $translated_text = __( 'Email Address', 'theme_text_domain' ); break; } } return $translated_text; }
add_filter('gettext', 'remove_admin_stuff', 20, 3); /** * Remove the text at the bottom of the Custom fields box in GeChiUI Post/Page Editor. * * @link https://codex.gechiui.org/Plugin_API/Filter_Reference/gettext */ function remove_admin_stuff( $translated_text, $untranslated_text, $domain ) { $custom_field_text = 'Custom fields can be used to add extra metadata to a post that you can <a href="https://codex.gechiui.org/Using_Custom_Fields" target="_blank">use in your theme</a>.'; if ( is_admin() && $untranslated_text === $custom_field_text ) { return ''; } return $translated_text; }
add_filter('gettext', 'change_admin_cpt_text_filter', 20, 3); /* * Change the text in the admin for my custom post type * **/ function change_admin_cpt_text_filter( $translated_text, $untranslated_text, $domain ) { global $typenow; if( is_admin() && 'MY_CPT' == $typenow ) { //make the changes to the text switch( $untranslated_text ) { case 'Featured Image': $translated_text = __( 'NEW FEATURED IMAGE TEXT','text_domain' ); break; case 'Enter title here': $translated_text = __( 'NEW TITLE COPY','text_domain' ); break; //add more items } } return $translated_text; }