apply_filters( ‘load_textdomain_mofile’, string $mofile, string $domain )

Filters MO file path for loading translations for a specific text domain.

Parameters

$mofilestring
Path to the MO file.
$domainstring
Text domain. Unique identifier for retrieving translated strings.

Source

$mofile = apply_filters( 'load_textdomain_mofile', $mofile, $domain );

Changelog

VersionDescription
2.9.0Introduced.

User Contributed Notes

  1. Skip to note 2 content

    An example that allows to override the default translations of a plugin:

    add_filter( 'load_textdomain_mofile', 'my_custom_translation_file', 10, 2 );
    
    /*
     * Replace 'textdomain' with your plugin's textdomain. e.g. 'hello-dolly'. 
     * Define your filename, such as: yourtranslationfile-en_GB.mo
     * Define the location, for example: wp-content/languages/textdomain/yourtranslationfile-en_GB.mo
     */
    function my_custom_translation_file( $mofile, $domain ) {
      if ( 'textdomain' === $domain ) {
        $mofile = WP_LANG_DIR . '/textdomain/yourtranslationfile-' . get_locale() . '.mo';
      }
      return $mofile;
    }

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