Replace Default Flags

1. Replace Default Flags — directly from the Advanced tab

​You can add a new flag for an existing language directly from the TP Settings –> Advanced tab –> Custom Language section.
​Basically, you add the information about an existing language, and just use another image for the flag.

Replace a Default Flag

2. Alternative Code Based Method

Note: if you are looking to replace the default flags in order to add a custom language to TP. Consult the documentation here.

You can replace the default flags in TranslatePress by using a bit of coding:

  • Create an empty plugin like this:
    https://gist.github.com/sareiodata/76f701e01db6685829db

    Since this plugin will contain the new flags, you’ll have to include the plugin file inside a folder like /tp_custom_flags as well as to create /tp_custom_flags/flags subfolder where the new ones will be found.

  • Add the following code to the end of it:
    /**
     * Change flags folder path for certain languages.
     *
     * Add the language codes you wish to replace in the list below.
     * Make sure you place your desired flags in a folder called "flags" next to this file.
     * Make sure the file names for the flags  are identical with the ones in the original folder located at 'plugins/translatepress/assets/images/flags/'.
     * If you wish to change the file names, use filter trp_flag_file_name .
     *
     */
    
    add_filter( 'trp_flags_path', 'trpc_flags_path', 10, 2 );
    function trpc_flags_path( $original_flags_path,  $language_code ){
    
    	// only change the folder path for the following languages:
    	$languages_with_custom_flags = array( 'en_US', 'es_ES' );
    
    	if ( in_array( $language_code, $languages_with_custom_flags ) ) {
    		return  plugin_dir_url( __FILE__ ) . '/flags/' ;
    	}else{
    		return $original_flags_path;
    	}
    }
  • Modify the code by editing the language codes list with the languages you wish to replace. In the example we are adding custom flags for languages en_US and es_ES. The rest of the flags will not change.
  • Make sure you place your desired flags in a folder called “flags” next to this file. Put both the folder and this file into another folder.
  • Make sure the file names for the new flags are identical with the ones in the original folder located at ‘plugins/translatepress/assets/images/flags/’.
  • Install this plugin via FTP (copy it inside wp-content/plugins) or create a zip archive with it and install it via the WordPress plugin upload functionality