Support » Plugin: TranslatePress - Translate Multilingual sites » Replacing self-uploaded images to replace flags?

  • Resolved wendy

    (@wendyma2011)


    Also wonder, if I can use self-uploaded images to replace the default flag images when indicating languages?

    Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Razvan Mocanu

    (@razvanmo-1)

    Hello,

    Yes, you can replace the default flags by using a bit of coding:

    • Create an empty plugin like this:
      https://gist.github.com/sareiodata/76f701e01db6685829db
    • 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

    If you need help with any of this, please let me know!

    Best regards,

    • This reply was modified 2 years, 2 months ago by Razvan Mocanu.
    wendy

    (@wendyma2011)

    Thank you so much Razvan!!!

    I will try it and let you know the result. It would be great if you put this function in your TranslatePress plugin, because many other people are interested in this. Some other popular translation plugins have this function.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Replacing self-uploaded images to replace flags?’ is closed to new replies.