Full Height Hero Banner Before Header with Sticky Header
In this tutorial, introducing how to create the full height hero banner before header with sticky site header. Header will display at bottom. After scroll header will be stick at top.
Method 1: Themer Part & Beaver Theme Header
Minimum Requirement:
Make sure that you already installed the following tools on your site.
- Beaver Theme
- Beaver Builder Plugin
- Beaver Themer addon
Creating full height hero banner part using Beaver Themer
- Navigate to Builder -> Theme Layouts
- Click on Add New button
- Enter title
- Type is “Theme Layout”
- Select “Part” from layout drop down
- Click on “Add Theme Layout” button
- You will redirect to next page
- Find Themer Layout Settings section
- Select “Page Open” position
- Set the location as per your requirement
- Click on Launch Page Builder button
- Create a full height hero banner
- Add ID “bh-hero-banner” into parent row. Hover on the row, click on rench icon, go to Advanced tab and enter bh-hero-banner into ID input field.
- Click on Done button and then publish the layout.
Creating fixed header
- Click on Appearance -> Customize sub menu
- Click on Header Panel
- Click on Header Layout section
- Select “Fixed” from Fixed Header drop down
- Click on Save & Publish button
Creating new JS file
- Create a folder “js” into your child theme folder if it is not there.
- Create a new file “bh-hero-banner.js” and add the following code
bh-hero-banner.js file
(function($){ if( $('.fl-builder-content #bh-hero-banner').hasClass('fl-row-full-height') ) { $('body').removeClass('fl-fixed-header'); var headerHeight = $('header.fl-page-header').height(); var height = $(window).height() - headerHeight; $('.fl-builder-content #bh-hero-banner').css('height', height); $(window).scroll(function(){ if( $(window).scrollTop() >= height ) { $('body').addClass('fl-fixed-header'); $('.fl-page-content').css('padding-top', headerHeight); } else { $('body').removeClass('fl-fixed-header'); $('.fl-page-content').removeAttr('style'); } }); } })(jQuery);
Enqueue JS file
Loading the new JS file “bh-hero-banner.js” on the site using wp_enqueue_scripts hook. Open the function.php file and add this snippet at end of the file
Enqueue the scripts
add_action( 'wp_enqueue_scripts', 'frame_before_header_hero_banner_scripts' ); function frame_before_header_hero_banner_scripts() { wp_enqueue_script( 'bh-hero-banner', get_stylesheet_directory_uri() . '/js/bh-hero-banner.js', array(), '1.0', true ); }
All done now. Browse your site and see the effect.
Method 2: Beaver Template & Beaver Theme Header
Minimum Requirement:
Make sure that you already installed the following tools on your site.
- Beaver Theme
- Beaver Builder Plugin
Creating hero banner using Beaver Template Post Type
- Navigate to Builder ->Templates
- Click on Add New button
- Enter Title
- Launch Page Builder
- Create Hero Banner as per your mind
- Add ID “bh-hero-banner” into parent row. Hover on the row, click on rench icon, go to Advanced tab and enter bh-hero-banner into ID input field.
- Click on Done button and then publish the layout.
Creating fixed header
- Click on Appearance -> Customize sub menu
- Click on Header Panel
- Click on Header Layout section
- Select “Fixed” from Fixed Header drop down
- Click on Save & Publish button
Displaying hero banner template before header on home page
Open the functions.php of your child theme and add the following snippet
Displaying hero banner before header
add_action( 'fl_page_open', 'frame_home_before_header_banner' ); function frame_home_before_header_banner() { if( ! is_front_page() ) return; FLBuilder::render_query( array( 'post_type' => 'fl-builder-template', 'p' => 859 ) ); }
Line no 1: fl_page_open hook is adding the hero banner before the site header.
Line no 4-5: Displaying the hero banner on home page only. I created static front page. So I used is_front_page() conditional tag. If you are using the default home page, then you will use is_home() conditional tag.
Line no 7-10: Rendering the BB template using FLBuilder::render_query() method.
Line no 9: 859 is my template ID. You will replace it with your template ID.
Creating new JS file
- Create a folder “js” into your child theme folder if it is not there.
- Create a new file “bh-hero-banner.js” and add the following code
bh-hero-banner.js file
(function($){ if( $('.fl-builder-content #bh-hero-banner').hasClass('fl-row-full-height') ) { $('body').removeClass('fl-fixed-header'); var headerHeight = $('header.fl-page-header').height(); var height = $(window).height() - headerHeight; $('.fl-builder-content #bh-hero-banner').css('height', height); $(window).scroll(function(){ if( $(window).scrollTop() >= height ) { $('body').addClass('fl-fixed-header'); $('.fl-page-content').css('padding-top', headerHeight); } else { $('body').removeClass('fl-fixed-header'); $('.fl-page-content').removeAttr('style'); } }); } })(jQuery);
Enqueue JS file
Loading the new JS file “bh-hero-banner.js” on home page only using wp_enqueue_scripts hook. Open the function.php file and add this snippet at end of the file
Enqueue the scripts
add_action( 'wp_enqueue_scripts', 'frame_before_header_hero_banner_scripts' ); function frame_before_header_hero_banner_scripts() { if( ! is_front_page() ) return; wp_enqueue_script( 'bh-hero-banner', get_stylesheet_directory_uri() . '/js/bh-hero-banner.js', array(), '1.0', true ); }
Live Preview: https://youtu.be/YCdcWI-4-js