Displaying Different Logos with WPML

WPML Languages
Living in Montreal, I often have to create multi-lingual websites for clients. That means finding the right plugin for the job. I don’t always use WPML, but it’s one of my go-to plugins when it comes to creating websites with multiple languages.
A recent client requested that their site display a different logo for each language. In order to make this happen, I had to code a simple conditional statement using PHP. But I needed to know which language was selected to display the right logo.
I wasn’t sure if WPML stored the current language selection so I had to do a bit of research. Thankfully, I discovered it did.

The Language Code

When a visitor selects a language, a two-letter language code is stored in the constant ICL_LANGUAGE_CODE. Using this and a little PHP, I wrote the following block of code to give my client what they wanted.


	

	

	

I placed that in header.php and used the class site-logo to style the CSS to match the client’s requested design.

Is there a better way?

If you take a closer look at the code above, you’ll notice that all the filenames have the language code as a prefix. That means you can simplify things even more which is always a better approach when it comes to coding.



Using the WPML plugin’s ICL_LANGUAGE_CODE constant lets you create all kinds of custom code specific to each language. Displaying different logos is just the tip of the iceberg.
NOTE: Konrad from WPML mentioned in a comment below a better way to get the current language code. It’s probably a good idea to use that one instead.

Share this:

Email
Facebook
Twitter
Pinterest
Pocket

Premium Themes for WordPress

Looking for an easy-to-use Premium Theme for WordPress? Check out Themes by bavotasan.com and have your site up and running in no time.

Use this WordPress website builder to build powerful websites in no time for your or your clients.

WordPress Hosting

WP Engine – designed from the ground-up to support and enhance the workflow of web designers.

Bluehost – providing quality web hosting solutions since 1996.

About the author

Picture of Luke Perrie

Luke Perrie