Description
add_action( 'wp_enqueue_scripts', function() { // Uncomment to disable in Elementor visual editor //if( \Elementor\Plugin::$instance->preview->is_preview_mode() ) { return; } wp_enqueue_script( 'jquery' ); wp_add_inline_script( 'jquery', " jQuery( function( $ ) { var header_selector = 'header.site-header'; $( window ).on( 'load resize scroll', function() { var header_height = $( header_selector ).outerHeight(); // Uncomment to make sticky after initial scrollby //if( window.pageYOffset <= header_height ) { return; } var admin_bar_height = $( '#wpadminbar' ).outerHeight(); admin_bar_height = $( '#wpadminbar' ).is( ':visible' ) && $( '#wpadminbar' ).css( 'position' ) === 'fixed' ? admin_bar_height : 0; $( header_selector ) .css( 'position', 'fixed' ) .css( 'top', admin_bar_height ) .css( 'left', 0 ) .css( 'width', '100%' ) .css( 'z-index', '1000' ); $( 'main' ) .css( 'margin-top', header_height + admin_bar_height ); } ); } ); " ); } );