Transparent Header Over the Homepage Hero
Lays the header over the first section of the homepage with a transparent background and white text, then switches to a solid header once visitors scroll.
Opens WPIDE on
Code
<style>
.wpide-overlay-header{position:fixed;top:0;left:0;right:0;z-index:999;background:transparent;color:#fff;transition:background-color .25s ease,color .25s ease,box-shadow .25s ease;}
.admin-bar .wpide-overlay-header{top:var(--wp-admin--admin-bar--height,32px);}
.wpide-overlay-header a{color:inherit;}
.wpide-overlay-header.is-solid{background:#ffffff;color:#111827;box-shadow:0 2px 12px rgba(0,0,0,.08);}
@media (prefers-reduced-motion:reduce){.wpide-overlay-header{transition:none;}}
</style>
<script>
(function () {
if (!document.body.classList.contains('home')) { return; }
var header = document.querySelector('header.wp-block-template-part, .site-header, #masthead');
if (!header) { return; }
header.classList.add('wpide-overlay-header');
var toggle = function () { header.classList.toggle('is-solid', window.pageYOffset > 60); };
window.addEventListener('scroll', toggle, { passive: true });
toggle();
})();
</script>
Notes
Works best when the homepage starts with a full-width Cover block. Adjust the solid colors and the header selector at the top.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.