We needed to output the language code for a form and needed to use a shortcode. We are using WPML (WordPress Multi Language) plugin and thus have access to Language constants, ie ICL_LANGUAGE_CODE
We needed to not only get the current language of the user, which was easy enough using a template tag, but needed it in shortcode format so that we could use it in widgets, gravity forms, etc.
Basically you set up a shortcode as you would normally in functions.php using ICL_LANGUAGE_CODE.
Here is the final snippet:
// Add Shortcode for Language function user_lang() { // Code return ICL_LANGUAGE_CODE; } add_shortcode( 'userlang', 'user_lang' );
Now use the shortcode within your posts, etc. You can see more about ICL_LANGUAGE_CODE at https://wpml.org/documentation/support/wpml-coding-api/ or check this thread out too if you are looking for language conditionals: https://wpml.org/forums/topic/conditional-language-shortcode/