0

In my footer.php I want to give people the option to change the language from english to german. I want to do this manually, because I have a lot of external links, so I do not want to use plugins since it should be easy with php.

All I need to do is to change the href and the content between the anchor.

<?php 
  session_start();
  if($_SESSION["language_is_german"])
  {
    echo "<a href='www.example.com?lang=en'>EN</a>";
    $_SESSION["language_is_german"] = true;
  }
  else
  {
    echo "<a href='www.example.com?lang=de'>DE</a>"
    $_SESSION["language_is_german"] = false;
  }
?>

This is the way I thought it might work, but it doesn't..

1 Answer 1

1

You cannot set PHP Variables in JavaScript:

onclick="$language_is_german = true"

The above code is not valid. You need to use Sessions for this! Or you need to use JavaScript for this. If you are using PHP, you can do something like this:

session_start();
$_SESSION["language_is_german"] = false;

And in the setting PHP, you can do something like this:

session_start();
$_SESSION["language_is_german"] = true;

Finally, your if has to be this way:

<?php 
    if($_SESSION["language_is_german"])
       echo "<a href='www.example.com?lang=en'>EN</a>";
    else
       echo "<a href='www.example.com?lang=de'>DE</a>"
?>
Sign up to request clarification or add additional context in comments.

7 Comments

I have updated my question, is this what you mean? And where do I find the setting PHP in wordpress?
@user1590534 It is better to use WordPress in Your Language for this! Check it out and let me know! :)
Thanks for that, but as I said earlier, I cannot use a plugin or anything else for this, since only the blog is done with wordpress, and everything else is static...
@user1590534 No plugin - this is a basic functionality addon for WP.
Mhm well, but I am using Wordpress in my language, I just want to give the user the possibility to view my website in english as well... I only need this button to toggle, then everything would be fine :-)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.