Title: gettext_with_context
Published: April 25, 2014
Last modified: February 24, 2026

---

# apply_filters( ‘gettext_with_context’, string $translation, string $text, string $context, string $domain )

## In this article

 * [Parameters](https://developer.wordpress.org/reference/hooks/gettext_with_context/?output_format=md#parameters)
 * [More Information](https://developer.wordpress.org/reference/hooks/gettext_with_context/?output_format=md#more-information)
 * [Source](https://developer.wordpress.org/reference/hooks/gettext_with_context/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/hooks/gettext_with_context/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/hooks/gettext_with_context/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/hooks/gettext_with_context/?output_format=md#user-contributed-notes)

[ Back to top](https://developer.wordpress.org/reference/hooks/gettext_with_context/?output_format=md#wp--skip-link--target)

Filters text with its translation based on context information.

## 󠀁[Parameters](https://developer.wordpress.org/reference/hooks/gettext_with_context/?output_format=md#parameters)󠁿

 `$translation`string

Translated text.

`$text`string

Text to translate.

`$context`string

Context information for the translators.

`$domain`string

Text domain. Unique identifier for retrieving translated strings.

## 󠀁[More Information](https://developer.wordpress.org/reference/hooks/gettext_with_context/?output_format=md#more-information)󠁿

This filter hook is applied to the translated text by the internationalization function
that handle contexts (`[_x()](https://developer.wordpress.org/reference/functions/_x/)`,`
[_ex()](https://developer.wordpress.org/reference/functions/_ex/)`, [`esc_attr_x()`](https://developer.wordpress.org/reference/functions/esc_attr_x/)
and `[esc_html_x()](https://developer.wordpress.org/reference/functions/esc_html_x/)`).

**IMPORTANT:** This filter is always applied even if internationalization is not
in effect, and if the text domain has not been loaded. If there are functions hooked
to this filter, they will always run. This could lead to a performance problem.

For regular translation functions such as `[_e()](https://developer.wordpress.org/reference/functions/_e/)`,
and for examples on usage, see `[gettext()](https://developer.wordpress.org/reference/hooks/gettext/)`.

For singular/plural aware translation functions such as `[_n()](https://developer.wordpress.org/reference/functions/_n/)`,
see `[ngettext()](https://developer.wordpress.org/reference/hooks/ngettext/)`.

For context-specific translation functions that also handle plurals such as `[_nx()](https://developer.wordpress.org/reference/functions/_nx/)`,
see filter hook `[ngettext_with_context()](https://developer.wordpress.org/reference/hooks/ngettext_with_context/)`.

## 󠀁[Source](https://developer.wordpress.org/reference/hooks/gettext_with_context/?output_format=md#source)󠁿

    ```php
    $translation = apply_filters( 'gettext_with_context', $translation, $text, $context, $domain );
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/l10n.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/l10n.php#L275)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/l10n.php#L275-L275)

## 󠀁[Related](https://developer.wordpress.org/reference/hooks/gettext_with_context/?output_format=md#related)󠁿

| Used by | Description | 
| [translate_with_gettext_context()](https://developer.wordpress.org/reference/functions/translate_with_gettext_context/)`wp-includes/l10n.php` |

Retrieves the translation of $text in the context defined in $context.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/hooks/gettext_with_context/?output_format=md#changelog)󠁿

| Version | Description | 
| [2.8.0](https://developer.wordpress.org/reference/since/2.8.0/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/hooks/gettext_with_context/?output_format=md#user-contributed-notes)󠁿

 1.  [Skip to note 2 content](https://developer.wordpress.org/reference/hooks/gettext_with_context/?output_format=md#comment-content-3405)
 2.   [leogermani](https://profiles.wordpress.org/leogermani/)  [  7 years ago  ](https://developer.wordpress.org/reference/hooks/gettext_with_context/#comment-3405)
 3. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fgettext_with_context%2F%23comment-3405)
    Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fgettext_with_context%2F%23comment-3405)
 4.     ```php
        /**
        * @param string $translated
        * @param string $text
        * @param string $context
        * @param string $domain
        * @return string
        */
        function example_gettext_with_context( $translated, $text, $context, $domain ) {
            if ( 'example-plugin' == $domain ) {
                if ( 'directions' == $text && 'directions on map' == $context ) {
                    $translated = 'map directions';  // not recipe instructions!
                }
            }
    
            return $translated;
        }
        add_filter( 'gettext_with_context', 'example_gettext_with_context', 10, 4 );
        ```
    
 5.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fgettext_with_context%2F%3Freplytocom%3D3405%23feedback-editor-3405)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fgettext_with_context%2F)
before being able to contribute a note or feedback.