apply_filters( “gettext_{$domain}”, string $translation, string $text, string $domain )

Filters text with its translation for a domain.

Description

The dynamic portion of the hook name, $domain, refers to the text domain.

Parameters

$translationstring
Translated text.
$textstring
Text to translate.
$domainstring
Text domain. Unique identifier for retrieving translated strings.

Source

$translation = apply_filters( "gettext_{$domain}", $translation, $text, $domain );

Changelog

VersionDescription
5.5.0Introduced.

User Contributed Notes

  1. Skip to note 2 content

    Changing Texts in Plugins using the gettext_domain Filter

    Sometimes, when working with WordPress plugins, you might want to customize the displayed texts to better match your website’s content or branding. The `gettext_domain` filter provides a simple way to achieve this by allowing you to modify specific text strings used by a plugin.

    Here’s a practical example of how to use the `gettext_domain` filter to change text strings in the context of the WP Document Revisions plugin:

    Suppose you’re using the WP Document Revisions plugin and want to replace the term “Owner” with “Submitter” in various instances throughout your site.

    You can achieve this by adding the following code snippet to your theme’s `functions.php` file or a custom plugin:

    add_filter( 'gettext_wp-document-revisions', 'wpdocs_change_wp_document_revision_strings', 10, 3 );
    /**
     * Code snippet to change the "Owner" text in the WP Document Revisions plugin
     *
     * @link https://developer.wordpress.org/reference/hooks/gettext_domain/
     */
    function wpdocs_change_wp_document_revision_strings( $translated_text, $text, $domain ) {
        if ( 'wp-document-revisions' === $domain ) {
            switch ( $text ) {
                case 'Owner':
                    $translated_text = 'Submitter';
                    break;
                case 'All owners':
                    $translated_text = 'All submitters';
                    break;
                case 'Document Owner':
                    $translated_text = 'Submitted by';
                    break;
    
                // Add more cases for other strings you want to change
    
            }
        }
    
        return $translated_text;
    }

You must log in before being able to contribute a note or feedback.