kwek-kwek
kwek-kwek

Reputation: 1343

Wordpress PHP Image change depending on a language

I am trying to write a piece of code that would allow me to change images or a whole block of a div depending on the language

<?php 
if($_SESSION['lang'] == "fr"){
    echo "images/header-fr-4.jpg";
}else{
    echo "images/header-4-en.jpg";
}
?>

Is there any other way of doing this in wordpress?

Upvotes: 0

Views: 2430

Answers (2)

Al.
Al.

Reputation: 2872

The Gengo plugin for WordPress supports translated posts and pages, as well as template elements depending on language. http://wordpress.org/extend/plugins/gengo/

For example:

<?php if (islanguage('en')) echo "You are reading in English"; elseif (islanguage('ja')) echo "You are reading in Japanese"; else echo "You are seeing all posts..."; ?>

Upvotes: 2

Tyler Carter
Tyler Carter

Reputation: 61577

You could do something like this:

$lang = $_SESSION['lang'];
die("SANATIZE YOUR VARIABLE");
echo "images/header-4-".$lang.".jpg";

You could always sanitize the variable in the header so you could use it throughout the entire script.

Upvotes: 0

Related Questions