Replace Default Flags

When adding new languages to your site using TranslatePress, you can choose to display the language flag of each language in your language switcher. Here’s how to replace the default image for each flag and change flags in TranslatePress.

How to change flags in TranslatePress

If you’re looking to replace the default flags for certain languages of your multilingual site you can use one of the two options below:

1. Replace default flags directly from the Advanced tab

​You can add a new flag for an existing language directly from TranslatePress Settings Advanced tab Custom Language section.
From here you can modify all the information about an existing language, or just use another image for the flag.

Change default flag in TranslatePress

Once you’ve uploaded and selected the new flag image make sure to click Save Changes.

You can read more about Custom Languages here.

2. Change flags using the alternative code-based method

Note: if you are looking to replace the default flags in order to add a custom language please 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.

Looking to go multilingual?

Get full access to TranslatePress and join 200.000+ website owners that grow their multilingual traffic.

Unlock PREMIUM Features

Or download FREE version