Skip to content

Instantly share code, notes, and snippets.

@melaniemuellerdesign
Last active January 20, 2019 15:08
Show Gist options
  • Select an option

  • Save melaniemuellerdesign/358f326b9ebe50163916f44c93cd74c1 to your computer and use it in GitHub Desktop.

Select an option

Save melaniemuellerdesign/358f326b9ebe50163916f44c93cd74c1 to your computer and use it in GitHub Desktop.
jQuery fixed header after scroll on wordpress
/*header script*/
function mobile_header_js() {
?>
<script>
jQuery(document).ready(function($) {
function fixed()
{
var window_top=$(window).scrollTop();
var top_position=$('body').offset().top;
var element_to_stick=$('.site-header');
if (window_top > top_position) {
element_to_stick.addClass('fixed-top');
} else {
element_to_stick.removeClass('fixed-top');
}
}
$(window).scroll(sticky);
fixed();
});
</script>
<?php }
add_action('wp_head', 'mobile_header_js');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment