How to add different header image for every page
-
Hi i was wondering how to add a different header image to every page on wordpress? thanks in advance
-
Also, it wouldn’t be home #banner. It would either be .home or body.home #banner.
A name on it’s own refers to a html element:
html
<body>
CSS
body {background: #fff; }
A name with a period in front, refers to a class:
`
html<body class='home'>
CSS
.home {background: #fff}
And a name with a # in front refers to an ID.
html
<body id='home'>
CSS
#home {background: #fff; }
CSS can be very frustrating as it is an incredibly complex subject but don’t worry, we’ll get you there.
to be honest with u m8 im lost right now i know the pages id apart from home its just https://localhost/wordpress/ and how do i put hte id into the css:
body.ID2 #banner {background: #fff url(images/WidgetTop.png) no-repeat top center;}lol my about page is ID2 sorry for confusion
OK, if your home page has no classes on the body tag, you can just use the body selector:
body #banner { background: url(images/bannerHome.png); }
Then, for your other pages, use the id:
body.page-id-560 #banner { background: url(images/bannerAbout.png) }
A tag and a class selector will over-ride just a tag on its own.
Right, load up your about page, then right-click anywhere in the browser window and hit ‘View Source’. Look for your <body> tag and see what classes you’ve got going on there. It will say something like
<body class='page page-id-506...'>
It’s the
page-id-506
you need to reference with your stylesheet.Your number will be different – if your ID is 2, it will be
body.page-id-2 {background: url(images/WidgetTop.png) no-repeat top center; }
Hmmmm i tryed it right now dident work??? :S there must be something wrong in my header.php so far in the header.php i got the important bit
in
</head>
<body <?php body_class(); ?>> under the </head> tagYou may want to try this plugin to see if it’s any easier than doing it all by hand:
maybe you can help me out if you see my freind website https://www.hellothemes.com/new thats basically what i want, only the homepage has a widget and the other pages dont wierd it doesnt work now but check the site when it works
Hi there, Im using marcovidor’s method and it works brilliantly:
<div class="banner"> <?php if(get_post_meta($post->ID, 'banner', true)) : ?> <img src="<?php echo get_post_meta($post->ID, 'banner', true); ?>" /> <?php else : ?> <?php the_title(); ?> <?php endif; ?> <div>
However, it doesn’t seem to work for posts as well. I know it probably wasn’t meant for posts, but I was just wondering if anyone knew how to adapt the code to include a custom header within posts as well. I would be very gratefull for your help.
Thanks
im using this method
PHP
<div id=”header” <?php if(is_page(‘About’)) : ?>class=”aboutpageclass”<?php else : ?>class=”normalclass”<?php endif;?>>
Css
.aboutpageclass { background-image:someimage.jpg; }
.normalclass { background-image:anotherimage.jpg }but i can get only the aboutpage to work now i want to do the rest of the pages, like contact, home , gallery but im stuck anybody can help me out be great thanks
expand it with ‘elseif’s https://www.w3schools.com/php/php_if_else.asp
for instance:
<?php if(is_page('About')) { echo 'class="aboutpageclass"'; } elseif(is_page('Contact')) { echo 'class="contactpageclass"'; } elseif(is_page('Home')) { echo 'class="homepageclass"'; } // continue with elseif lines // else { echo 'class="normalclass"'; } ?>
Hi! I’m a fresh newbie in WP. I love to change and create my own WP header but it seems too difficult for me to do so, compared to blogger.com
By the way, there is 12 new niche site themes for WordPress such as Computer and internet-related niches, Mortgage and home-related niches, and other more. You can take a look on them here.
All that niche sites is SEO friendly menu automatically generated based on WordPress page titles, with high CTR AdSense placement on every page.
nice to share with you guys.
thank you alchymyth you a genius it works thank you very much
I used marcovidor’s solution
<div class="banner"> <?php if(get_post_meta($post->ID, 'banner', true)) : ?> <img src="<?php echo get_post_meta($post->ID, 'banner', true); ?>" /> <?php else : ?> <?php the_title(); ?> <?php endif; ?> <div>
and with some hacking (had to erase a default header that my theme got built in to the functions.php file & adapt widths of the header) got it to work great!
I’m trying to add a different background image to each page.
I tried the below code and it works for the header but how do I place it in the background.<div class="banner"> <?php if(get_post_meta($post->ID, 'banner', true)) : ?> <img src="<?php echo get_post_meta($post->ID, 'banner', true); ?>" /> <?php else : ?> <?php the_title(); ?> <?php endif; ?> <div>
I figure it out.
super simple code with the addition of the body class
- The topic ‘How to add different header image for every page’ is closed to new replies.