Last active
March 19, 2018 11:50
-
-
Save SiGaCode/3c7cc21344e6f7a269b8cc82808faa3b to your computer and use it in GitHub Desktop.
A sticky footer for the GeneratePress theme which will stick to the bottom when the content isn´t long enough and just scroll like a normal footer otherwise.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For testing purpose, I added this script to a GP hook (wp_head) and had it run for only the test page named "Stickytest". To be valid for the whole site, you might want to enqueue the script. | |
<?php if ( is_page( 'stickytest' ) ) : ?> | |
<script> | |
jQuery(document).ready(function($) { | |
$(window).resize(function(){ | |
var footerHeight = $('.site-info').outerHeight(); | |
var stickFooterPush = $('.push').height(footerHeight); | |
$('.contentwrapper').css({'marginBottom':'-' + footerHeight + 'px'}); | |
}); | |
$(window).resize(); | |
}); | |
</script> | |
<?php endif; ?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Add to childtheme CSS file or CSS snippets plugin of your choice */ | |
html, body { | |
height: 100%; | |
} | |
.contentwrapper { | |
min-height: 100%; | |
height: auto !important; | |
height: 100%; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Add to childtheme functions or PHP plugin of your choice | |
// Add custom opening div tag | |
add_action( 'generate_before_header', 'opening_div' ); | |
function opening_div() { | |
echo '<div class="contentwrapper">'; | |
} | |
// Add custom closing div tag including push container | |
add_action( 'generate_before_footer', 'closing_div' ); | |
function closing_div() { | |
echo '<div class="push"></div></div>'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment