Wordpress Theme - Header Switcheroo

Posted on 2009-04-26
Last Modified: 2012-08-14
I've created a theme for a Wordpress site I'm developing and have installed a nifty little plugin that allows you to toggle back-and-forth with the language of the content (the plugin is called qTranslate -

Anyway, the plugin works great but there are a number of things that need to be manually edited in order to get a site working seamlessly between languages.

The issue I'm having is that I need to use two different headers (in order to switch the logo image and navigation CSS sprite). In my index.php file, I am trying to figure out how to create somesort of IF statement that will toggle the "header.php" file that gets imported.

For example, by default the header.php file is loaded but if a user toggles the site language to French, I would like it to load a header_fr.php file.

With that said, I'm not entirely sure if its the best way to go about it since the <?php get_header(); ?> function is on more pages then just the index.php file. If anyone has any suggestions, it would be much appreciated.

P.S. I tried looking through the qTranslate support forum but have issues using their search. Apparently I'm never specific enough...
Question by:Adam
    LVL 3

    Accepted Solution


    I think you could go like this on the top of the index.php:

    if(lang == French){
    elseif(lang == English){

    I dont know how you define what languages is active in the database so you have to replace "lang == French and lang == English with some definition.

    A more simple way is to just change the header div and use the same header.php for all languages.

    if(lang == French){
        echo "<div id="french_header">Welcome Lé French</div>";
    elseif(lang == English){
        echo <div id="english_header">Welcome you English speakin</div>";
    LVL 1

    Author Comment

    Okay, so I looked into it and I think an example of that would look something like the sample below.

    However, my screen is now coming up blank when I use the code. I'm not really an expert in PHP but am I missing a quote or something that would cause this to not work?

    Let me know if more details are required.

       $lang = qtrans_getLanguage();
       if ($lang=="en"){
       	echo "<h1 id="logo_en">Test_EN</h1>";
       	echo "<h1 id="logo_fr">Test_FR</h1>";
    <?php endif; ?>

    Open in new window

    LVL 1

    Author Comment

    I just realized that the last tag should be " ?> " and not "<?php endif; ?>".

    However, I still seem to be having the same issues. Am I missing something?

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Join & Write a Comment

    Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
    Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit ( and similar technologies have enjoyed wide adoption, making it possib…
    The purpose of this video is to demonstrate how to set up basic WordPress SEO. This will be demonstrated using a Windows 8 PC. The plugin used will be WordPress SEO by Yoast. Go to your WordPress login page. This will look like the following: myw…
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now