Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

2 Answers 2

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

 
discard

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.