Call different header images per page

Hello. I’d like to call a diff header image depending on the page i am on.
I have this code that chaneges the background of the page…

    	echo'<div id="mainBground" class="mainBg">';
    }else if(is_page('fortExtant')){
			echo'<div id="mainBground" class="ftEBg">';	
    }else{
      echo'<div id="mainBground" class="other">';
    };?>```
so far so good. Wanted to see if i could use something along those lines for the header, But not quite sure how to get about it & so far have not found how to echo a specific image for the this tag,
get_header_image()
Can i get some advice on this please?
thx
D

Have you considered just echoing a different class each time, and serving the image as a background? That’s the way to go if the image is just decoration.

Hello Ralph. So if i understand your suggestion correctly…you’d be saying don’t use the <?php header_image(); ?> tag, create a div for the image instead, gv it a background image and change the class w/the respective image according to page?
I’ll try it. good idea.
But must admit i’d still like how to use the tag instead. But will try out your suggestion.
Thx

I’m not quite clear on what the images are for, but if for decoration only, I’d set them as a background image on an existing element with classes, yes.

they are just the header image.
I want a main image, but or a couple of pages a different one.
and was wondering when it comes to code
how could i incorporate in this bit, i tried adding two extra echo lines(also w/out the ; & with a , or w/no putnction) and that didn’t work?

<?php if(is_page('home')){
echo'<div id="mainBground" class="mainBg">';
}

else if(is_page('fortExtant')){
echo'<div id="mainBground" class="ftEBg">';
echo'<div id="b" class="classB">';
echo'<div id="c" class="classC">';

	
}else{
echo'<div id="mainBground" class="other">';
};?>

thank you

Actually that was a very nice suggestion i just created an entirely blank page since & won’t need the wp tags for it.However…I need to call in the stylesheet. and so far none of these have worked

 <style src="<?php echo  get_template_directory_uri(); ?>style.css"></style>
 <style src="<?php get_template_directory_uri(); ?>style.css"></style>
 <style src="style.css"></style>

Would rather have an external stylesheet. Any advice on how i can solve this part?
thx
D

Write this code on header.php

<?php
    if ( is_front_page() ) 
           { ?>
              //put your html code of  front page header 
                
         <?php } else 
        {  ?> 
       //put your html  header code of other pages 
         <?php  }  ?>

EDIT
This post has been reformatted by enclosing the code block in 3 backticks
```
on their own lines.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.