Support » Theme: Radiate » Different header images depending on page

  • Hello.

    I wanted to know if it is possible to use different imagens for different pages. In my case I wanted to show bigger sized images on the front page and smaller ones for all others. Programming is not a problem as I’m not new to html, php, javascript or css.

    I’ve been tinkering around the code but I’m new to wordpress and still haven’t figure out where the “randomising process” of the image is. I was thinking of adding a condition there to only randomise certain images, if it is the front page (or ask for a new one if it is not the one I want).

    Thank you for your time.

Viewing 4 replies - 1 through 4 (of 4 total)
  • I have ended up solving this problem, if anyone happens to want the same thing, by re-implementing the function radiate_internal_css, located on the extras.php file, on my child’s theme functions.php file.

    The code is basically the same except that substituted this:

    $header_image_height = get_custom_header()->height;
    if ( is_user_logged_in() ) { $height = $header_image_height - 32; }
    else { $height = $header_image_height; }
    $heightsmall = $height - 68;
    $header = get_header_image();

    By this:

    if(is_home()) {
    	$header = get_stylesheet_directory_uri() . "/images/header-home/" . rand(0, 2) . ".jpg";
    	$height = 750; //This number represents the home image height.
    else {
    	$header = get_stylesheet_directory_uri() . "/images/header-others/" . rand(0, 2) . ".jpg";
    	$height = 450; //This number represents the other pages image height.
    if ( is_user_logged_in() ) $height-= 32; // Login bar height.
    $heightsmall = $height - 68;

    I also had to add two folders on my child’s theme images folder. One with the name header-home and another with the name header-others. The first one has the header images that I want on my home page and the other the ones I want on the other pages. The sizes I attribute to $height are the sizes of the respective header images.

    I also had to add the if ( ! function_exists( 'radiate_internal_css' ) ) : before the function in extras.php begins and endif; after the function ends so that my function on the child theme works. I would like to ask, if possible, for the developer to add this if condition on the next updates, so that I don’t have to add it every time there is a new update. Thank you.

    Sorry for the double post. I forgot to mention that the images on the folders are numbered from 0 to 2. If you want more than 3 you have to change the second number (2) on the rand function to the number of your last picture (number of pictures on the respective folder – 1). The function gives a random number on the entered interval.

    You also need to change .jpg to another format in case you are using a different one. With the current code, It is important that all images are on the same format.

    Many thanks, Sol1dus, for posting this nifty bit of coding.
    I have been trying to do the same thing you managed to elegantly accomplish. But for me, being new to PHP, Javascript and CSS, programming definitely IS a problem.
    You have undoubtedly saved me several days of fumbling around in frustration and many of the few hairs I have left on my head.
    In gratitude,

    You’re welcome. Glad I could help by posting my own solution. 🙂

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Different header images depending on page’ is closed to new replies.