WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have in the following code in the template:

<img src="<?php header_image(); ?>" />

However, I want to change this image according to the language selected (through GET parameter lang).

The question is, how to change this function to look for different images according to the received GET parameter?

I thought of:

  1. Change this code on header.php to a fixed image path, so I could put an if and choose between the images I want.
  2. Replace the result of the function get_header_image() and use it instead on header.php according to the received parameter, sort of replacing the string suffix .png to _en.png or .png to _es.png.
  3. Change the header_image() function to behave the way I want.

All these ways look ugly to me. Are there better ways?

share|improve this question
up vote 1 down vote accepted

Filter the get_theme_mod() function (wp-includes/theme.php):

add_filter( 'theme_mod_header_image', 'localized_header' );

function localized_header( $img )
    // Do something awesome with the $img path.
    return $img;
share|improve this answer

I used second approach (I'm posting what I did as it may be helpful to someone):

    <img src="<?= 
       isset($_REQUEST['lang']) ? 
          (str_replace('.jpg', '_' . $_REQUEST['lang'] . '.jpg', get_header_image())) 
          : get_header_image() 
     ?>" width="<?php echo HEADER_IMAGE_WIDTH; ?>" height="<?php echo HEADER_IMAGE_HEIGHT; ?>" alt="" />
share|improve this answer
Never use request arguments without escaping! Use esc_attr() instead. – toscho Jun 6 '11 at 18:50

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.