Using WordPress ‘gettext’ PHP filter

The gettext WordPress PHP filter allows you to modify the translated text output.

Usage

add_filter('gettext', 'your_custom_function', 10, 3);
function your_custom_function($translation, $text, $domain) {
  // your custom code here
  return $translation;
}

Parameters

  • $translation (string) – Translated text.
  • $text (string) – Text to translate.
  • $domain (string) – Text domain. Unique identifier for retrieving translated strings.

More information

See WordPress Developer Resources: gettext

Examples

Change the “Read More” text

Customize the “Read More” text that appears on the blog page.

add_filter('gettext', 'change_read_more_text', 10, 3);
function change_read_more_text($translation, $text, $domain) {
  if ($text === 'Read More') {
    $translation = 'Continue Reading';
  }
  return $translation;
}

Modify the “Leave a Reply” text

Change the “Leave a Reply” text on the comments form.

add_filter('gettext', 'modify_leave_a_reply_text', 10, 3);
function modify_leave_a_reply_text($translation, $text, $domain) {
  if ($text === 'Leave a Reply') {
    $translation = 'Share Your Thoughts';
  }
  return $translation;
}

Change the “Search” button text

Customize the “Search” button text on the search form.

add_filter('gettext', 'change_search_button_text', 10, 3);
function change_search_button_text($translation, $text, $domain) {
  if ($text === 'Search') {
    $translation = 'Find';
  }
  return $translation;
}

Update the “No Comments” text

Modify the “No Comments” text displayed when there are no comments on a post.

add_filter('gettext', 'update_no_comments_text', 10, 3);
function update_no_comments_text($translation, $text, $domain) {
  if ($text === 'No Comments') {
    $translation = 'Be the First to Comment';
  }
  return $translation;
}

Change the “Categories” widget title

Customize the “Categories” widget title in the sidebar.

add_filter('gettext', 'change_categories_widget_title', 10, 3);
function change_categories_widget_title($translation, $text, $domain) {
  if ($text === 'Categories') {
    $translation = 'Topics';
  }
  return $translation;
}