This tutorial enables you to add a hero image with overlaying content behind your site header and nav menu like this :
Tested using the latest version of the Genesis Sample child theme by StudioPress, this solution works with or without Gutenberg blocks on the home page.
Demo Video
Shows a full screen width image behind the site header and menu in the Genesis Sample theme. Shows the image can be changed using the Hero Image setting in the customizer. Displays HTML content from the Hero Text widget area.
Installation Steps
There’s 4 steps :
- # Upload the files named front-page.php and hero.js to the your theme folder like this :
- # Copy & paste the PHP code from functions.php file to the end of your Genesis Sample themes functions file
- # Copy & paste the CSS from the style.css file to the end of your themes style sheet and clear caching.
- # From your WordPress Dashboard, go to Appearance > Widgets and copy the demo HTML for the hero text into a HTML widget in the Hero Text widget area.
Once you’ve completed the steps, you can then add a image using the customizer or upload an image file named hero.jpg directly to your child themes images folder.
I have two issues with this front page hero image. There is space top of the hero image on the Chrome and Firefox. It doesn’t work with Safari at all. Can you help about this issue? Here is the url: https://wcscl.wpengine.com/
Hello Lobsang
As seen in the demo video, it works perfectly.
Please clear caching as instructed in the installation steps and turn off minification so i can take a look at where you added the CSS.
Otherwise, send me a copy of your theme with the code installed.
I installed the code in a fresh copy of Genesis Sample 3.4.2 and tested it using Chrome, MS Edge, Firefox & Safari
https://youtu.be/By0ms50bao0
Thanks.
Hello,
I’ve just downloaded the folder and it does not have the front-page.php in it. I’ve got the acf.json, functions.php, hero.js and style.css but that’s it.
Please advise
Tim
It’s in there, i checked the download folder. There’s no .json file for this tutorial.
Apologies, Brad, I see the front-page.php file is there and I’ve confused two different Hero Image installations.
Yes i normally publish multiple tutorials using different methods but this one doesn’t use ACF.
Hi, how do I get the text on the hero image overlay to wrap properly on mobile devices? When I view my homepage https://loveweddingphotosandfilm.co.uk on a mobile device, the word ‘Wedding’ has the letter ‘g’ moved down onto the next line – the text reads:
Love
Weddin
G Photos
And
Film
How do I get the letter ‘g’ to not drop onto the next line without reducing the font size?
Thank you.
You could remove the left and right padding
Hi, that worked just great, thank you.
Hi Brad,
When I add the hero image I notice that my homepage fails the Cumulative Layout SHift test on pagespeed insights.
Can this be fixed so I can still use a hero image but pass the CLS test?
This is important as from next month, Google is taking CLS into account in its ranking algo.
Many thanks.
Resolved – I’d been tweaking the CSS but resetting it back to default resulted in CLS score of zero. Perfect.
Hello! ๐ This works great except I’m getting like a 30px gap at the top. The theme hasn’t been changed much yet, so I’m not sure what’s causing that. Any ideas? No changes were made to the standard sample theme in terms of the site header or anything and I can’t seem to find anything in the CSS that indicates a gap or a positioning issue. The image may not be the exact same dimensions, though, so perhaps that’s it?
Where’s the gap? Please link to your site. You may be using a different version of Sample to the one the code is tested in so you’ll need to add/modify the CSS.
Ah. I had to adjust the CSS here:
@media only screen and (min-width: 960px)
.hero-active .site-container {
top: -73px;
position: absolute;
}
Making it -100 fixed the issue. ๐
Hi, its me again. ๐ Curious, on interior pages, it’s not showing a white background on the site header as you scroll down the page, which does pose an issue. Is there a way to ensure that happens on all the pages? Thank you!
This tutorial clearly states front page.
Okay, cool. I figured there might be a solution that was simple or someone else might’ve asked about it. That’s fine. I’ll figure it out.
FWIW, I just set the main site-header background back to #fff and that seems to resolve it. I was concerned that would override the hero stuff, but it didn’t based on where I placed your CSS. In case anyone else runs into this.
I was previously using Layerslider, and it would display the full height of the image even on a mobile device, as you move up to larger screens, such as my desktop, the image would display more of the width, and if you rotate the screen to landscape proportions,m it would display the entire image.
How do I change CSS to display full height, the above doesn’t work on all proportions of screen? Thank you.
I don’t have the CSS for this as its something i would need to spend some time on to work out but it would involve modifying the default CSS i provided with new values in order to work with your new image size. I do provide limited PHP modification support included in membership at no additional charge however CSS modifications are either billable or something you will need to spend time on yourself.
Thanks, I did that, and it works up to about 90% full screen, then when I go full screen it cuts off the bottom of the image – it’s like it wants to do full width but not full height.
Hi, the default hero image size is 1600 x 800, how do I change this to accommodate a larger image, say 1920 x 1080? Thanks.
Link to your site please. You can change the values in the CSS.
Hi Brad, it’s https://loveweddingphotosandfilm.co.uk/
Ideally, I want to be able to add an image with the proportions of 6 x 4, thank you.
Try changing the value for the height in this CSS rule
Thanks. I already have this in my css file:
I tried changing height: 100% to height: 100vh; but the image still doesn’t display full height, it’s cropping the image when viewed on a desktop.
Add another rule after that one and clear caching. It worked when i tested it in the browser.
ok! I will double check and make sure I did not mess up any code because it is not showing up transparent for me after uploading my logo
If you also want it transparent on scroll, add this CSS to the end of your style sheet and clear caching :
Not sure whats going on, but i followed the steps exactly and the image is not showing
I emailed you a copy of the text theme which includes the code installed. Did you add a widget to the widget area? Otherwise please send me FTP access.
Thanks for sending it! It is working perfectly now! ๐
I’m sorry actually is there a way to make the header transparent when a logo image is present?
The site header is transparent when a logo is added using Customize > Site Identity > Logo