Archived topic
Switch header background image using elements ?
9 replies · Started by Radek on October 4, 2018
Hi, what is the best way to change header background image for one category only ? Trying use elements, but no luck. FB question with picture for better imagination here: https://www.facebook.com/groups/generatepress/?multi_permalinks=1832469000142002¬if_id=1538592516614317¬if_t=feedback_reaction_generic
Thanx
Hi there,
so its only one category archive page that you want to swap the header background image?
Can you share a link to the specific pages - you can edit the original topic and use the Site URL for privacy.
No, it'll be for more categories. Each category (archive page + all category posts) will have own header background image...
Site is under http password protection, so if You'll need, I can send You some login info.
Thanx a lot
How many categories do you reckon it will need? Just looking at what the easiest solution would be
Just 2 for this moment
OK, so for now, easiest to just target the body class of the categories with this CSS, just add as many rules as you need and add the correct slug.
.category-slug .site-header {
background-image: url('image_url');
}
Working for category archive, but not for category posts...
Ok, so lets try the Hooks method.
New Element Hook - use the WP_Head hook. Add this in the hook with the correct image URL:
<style type="text/css">
.site-header {
background-image: url('image_url');
}
</style>
Then you can set the Display rules using
Posts: Post Category select the category and the same for Post Archives: Post Category Archive
Exactly what I was trying before, but with bad style syntax (post at FB). Your version works perfect ;)
Thanx a lot for Your time.
Awesome :) Glad i could be of help