Skip to content

Instantly share code, notes, and snippets.

@anandkumar
Last active December 16, 2015 12:19
Show Gist options
  • Save anandkumar/5433719 to your computer and use it in GitHub Desktop.
Save anandkumar/5433719 to your computer and use it in GitHub Desktop.
Add Sticky Sharebar to Genesis Framework (Tutorial link: http://www.blogsynthesis.com/?p=1090)
/*
* Add Sharebar Box on Single Posts - Genesis
* Tutorial link: http://www.blogsynthesis.com/?p=1090
* @author Anand Kumar
*/
// Enqueue sticky sharebar script
add_action( 'wp_enqueue_scripts', 'blogsynthesis_sb_enqueue_script' );
function blogsynthesis_sb_enqueue_script() {
wp_enqueue_script( 'sticky-menu', get_stylesheet_directory_uri() . '/js/sticky-sharebar.js', array( 'jquery' ), '', true );
}
add_action('genesis_post_content', 'include_share_bar', 3 );
function include_share_bar() {
if ( is_single() )
require(CHILD_DIR.'/sharebar.php');
}
<!-- Place these tags at the end of html. -->
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
<script type="text/javascript">
(function() {
var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
po.src = 'http://apis.google.com/js/plusone.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
})();
</script>
<script type="text/javascript" src="http://static.bufferapp.com/js/button.js"></script>
<div id="fb-root"></div>
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<!-- START BlogSyntheis Sharebar for Genesis Framework. -->
<div id="social-widgets" class="social-widgets">
<div class="social-share-txt">Share:</div>
<div class="social-widget facebook-widget">
<div class="fb-like" data-href="<?php echo get_permalink(); ?>" data-send="false" data-layout="button_count" data-width="62" data-show-faces="false"></div>
</div>
<div class="social-widget google-widget">
<div class="g-plusone" data-href="<?php echo get_permalink(); ?>" data-size="medium"></div>
</div>
<div class="social-widget twitter-widget">
<a href="https://twitter.com/share" class="twitter-share-button" data-text="<?php the_title(); ?>" data-url="<?php the_permalink(); ?>" data-via="TWITTER_HANDLE" data-related="TWITTER_RELATED">Tweet</a>
</div>
<div class="social-widget twitter-widget">
<a href="http://bufferapp.com/add" class="buffer-add-button" data-text="<?php the_title(); ?>" data-url="<?php echo get_permalink(); ?>" data-count="horizontal" data-via="TWITTER_HANDLE" >Buffer</a>
</div>
</div>
<div class="clear"></div>
<!-- SHARE-BAR END More info: http://www.blogsynthesis.com/?p=1090 -->
jQuery(document).ready(function ($) {
$(document).ready(function () {
var top = $('#social-widgets').offset().top;
$(window).scroll(function (event) {
// what the y position of the scroll is
var y = $(this).scrollTop();
var maxY = $('#respond').offset().top;
// whether that's below the form
if (y >= top && y < maxY) {
// if so, ad the fixed class
$('#social-widgets').addClass('fixed');
} else {
// otherwise remove it
$('#social-widgets').removeClass('fixed');
}
});
});
});
/* Floating Sharebar CSS (Tutorial link: http://www.blogsynthesis.com/?p=1090)
------------------------------------------------------------ */
.social-widget {
float: left;
margin-right: 10px;
padding: 2px;
min-width: 92px;
}
.social-widgets {
border-bottom: 1px solid #d2d2d2;
height: 28px;
bottom-top: 4px;
padding: 10px;
}
.social-widgets.comm {
float: left;
padding: 0 20px;
}
.social-widgets.fixed {
position: fixed;
background: #fff;
top: 0;
z-index: 5000;
box-shadow: 0 2px 1px rgba(0, 0, 0, 0.15);
-moz-box-shadow: 0 2px 1px rgba(0, 0, 0, 0.15);
-webkit-box-shadow: 0 2px 1px rgba(0, 0, 0, 0.15);
width: 600px; // must be matched with your entry-content width
}
.social-share-txt {
font-size: 14px;
font-weight: bold;
float: left;
margin-right: 12px;
line-height: 23px;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment