# Load Your Own Translation Files First

> Looks for custom .mo files in wp-content/languages/custom/ before the official ones, so your edited translations of a plugin or theme survive updates.

- Type: PHP
- Runs: Run everywhere
- Category: [Multilingual](https://wpide.com/library/category/multilingual/)
- Tags: translations, mo-files, overrides
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/i18n-custom-translation-overrides/

## Code

```php
add_filter( 'load_textdomain_mofile', function ( $mofile, $domain ) {
    static $loading = array();

    if ( isset( $loading[ $domain ] ) ) {
        return $mofile;
    }

    $custom = WP_LANG_DIR . '/custom/' . $domain . '-' . determine_locale() . '.mo';

    if ( is_readable( $custom ) ) {
        $loading[ $domain ] = true;
        load_textdomain( $domain, $custom ); // Loaded first, so its strings take priority.
        unset( $loading[ $domain ] );
    }

    return $mofile;
}, 10, 2 );
```

## Notes

Name files like plugin-slug-fr_FR.mo (or theme-slug-de_DE.mo) and upload them to wp-content/languages/custom/. Strings missing from your file still come from the official translation.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Load Your Own Translation Files First" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
