Halloween Sale 15% off Ends in See the plans
HTML

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.

Don’t have WPIDE yet? Install it on your site

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

  1. Install WPIDE on your WordPress site (it is free) and open Code Snippets.
  2. Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
  3. It is added inactive: review the code and settings, then switch it on.

Have a snippet worth sharing?

Publish it to the library from WPIDE or right here. Sign in with any WordPress site that runs WPIDE, free or Pro. Public snippets are reviewed by the WPIDE team before they appear.

Which site should get this snippet?

Enter the address of your WordPress site. WPIDE opens there in a new tab with the snippet ready to review and save.

Remembered in this browser only, so you are asked once.

Report this snippet

Tell the WPIDE team what is wrong: broken code, something harmful, spam or copied work.