Kick ass piece of PHP code for use with WordPress and WPML

multilingual-headache

I'm no programmer, but I know enough to get by and earn a good living in graphic design. That doesen't stop me from wanting to pull my hair out and set my computer on fire when I can't get the simplest programming issues fixed quickly.

For the last year or so I have become a huge fan of WordPress and because I live in Montreal, almost every web project has to be bilingual in French and English.

The WPML plugin is a wonderful add on which makes smart multilingual sites a reality for non programmers like myself.

Sometimes though, the plugin can't do everything when it comes to certain themes that have content that is out of WPML's reach.

The following piece of code has been saving my life a lot lately when it comes to stubborn themes.

<?php if(ICL_LANGUAGE_CODE=='fr'): ?>
Content and code here
<?php elseif(ICL_LANGUAGE_CODE=='en'): ?>
Content and code here
<?php endif;?>

Sooooooooo simple and it works for just about anything an annoying theme can throw at you.

The simplest and best example is the first time I ever ran into a problem and couldn't figure out how to get the blurb under my logo on this site to show in the right language. In the php file that contained the code that displayed the logo/blurb, I changed the code from this:

<a href="<?php echo get_option('home'); ?>"><img src="<?php echo stripslashes($theme_options[$shortname.'_logo']) ; ?>" alt="" /></a>

To this:

<?php if(ICL_LANGUAGE_CODE=='en'): ?>
<a href="http://funkydragon.ca/"><img src="http://www.funkydragon.ca/images/funkydragon-logo.png" /></a>
<?php elseif(ICL_LANGUAGE_CODE=='fr'): ?>
<a href="http://funkydragon.ca/fr"><img src="http://www.funkydragon.ca/images/funkydragon-logofr.png" /></a>
<?php endif;?>

That's it! Hope this little bit of code helps someone as much as it has helped me :)