Wordpress Themes - WP Forum at BFA

Wordpress Themes - WP Forum at BFA (http://forum.bytesforall.com/index.php)
-   Header configuration & styling (http://forum.bytesforall.com/forumdisplay.php?f=15)
-   -   Switch header image depending on wordpress category using a background image (http://forum.bytesforall.com/showthread.php?t=23672)

Jerry_Q4d Nov 18, 2016 12:18 AM

Switch header image depending on wordpress category using a background image
 
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...

juggledad Nov 18, 2016 05:00 AM

I think it is a pretty clever idea!

As of what the search engines will think..who knows, if they are not ok with it today, next week they might change their algorithms and it might be ok. The only way to tell would be to look at your rankings now, make the change and check them in a month.


All times are GMT -6. The time now is 03:56 PM.

Powered by vBulletin® Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.