Dear people! Im running a wordpress installation where I use different images in my header, depending on the category of the wordpress post or page in question. So I have a category "Tech" with a different header image than category "About us", etc.
Until today I have been doing this with a simple trick: by defining all header images in my html, but setting them to "display:none;"
This makes them invisible to the user. When a wordpress post or page with the category in question is accessed, my css displays the right image by setting it "display:inline;"
This works nicely across all browsers, but it has a disadvantage: all images have to be loaded, of course, they are just hidden. So it creates unnecessary server load, and since I plan to use a lot of new categories in the future, I have to do this in a better way.
I know there are plugins to switch the header depending on the category, but they were not too stable when I tried them last time, and with Atahualpa I thought there would be a better way.
What I have come up with is simple: Instead of displaying or hiding header images, I could just display no image at all at the start. Then, if a user accesses a post from category "Tech", the css could load the necessary header image as a background-image.
Code in the header (just a div to take the image):
<div id="#my_custom_header_image"></div>
Code in css inserts in Atahualpa:
body.archive.category.category-tech #my_custom_header_image {
height: 100px;
width: 200px;
background-image:url(http://..myimage.jpg);
}
So images are loaded on demand, and I need neither plugins nor javascript or anything. Its just important to remember that you must always define the size of the background-image, otherwise it may happen that it is not displayed at all (thats the way background images work in html, as I see it).
What do you think of this method? Can I do this or does it have disadvantages? Im a little concerned what search engines make of this, or if it could break things because its not really what background-images are meant for. But tempting...