Skip to content

Instantly share code, notes, and snippets.

@anandkumar
Last active December 18, 2015 15:29
Show Gist options
  • Save anandkumar/5804994 to your computer and use it in GitHub Desktop.
Save anandkumar/5804994 to your computer and use it in GitHub Desktop.
Genesis Sticky Social Sharebar (v2.0) (includes tweet, fb like, G+ and buffer buttons. Tutorial link: http://www.blogsynthesis.com/?p=1090) I have just updated the code for the old tutorial. Now it supports Genesis 2.0 and Responsive design. Follow the tutorial for easy installation to your Genesis based Wordpress sites.
<!-- Place these tags at wp_footer() from Genesis Dashboard. -->
<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>
<?php
//* Do NOT include the opening php tag and
//* Must read the tutorial at http://www.blogsynthesis.com/?p=1090
//* Add Sharebar to Posts
add_action('genesis_entry_content', 'include_share_box', 3 );
function include_share_box() {
if ( is_single() )
require(CHILD_DIR.'/sharebar.php');
}
// Share bar
if ($('body').hasClass('single')) {
var timeout = null; var entryShare = $('#social-widgets').first(); var entryContent =$('.entry-content').first();
$(window).scroll(function () {
var scrollTop = $(this).scrollTop();
if(!timeout) {
timeout = setTimeout(function() { timeout = null;
if (entryShare.css('position') !== 'fixed' && entryShare.offset().top < $(document).scrollTop()) {
entryContent.css('padding-top', entryShare.outerHeight() + 8);
entryShare.css({'z-index': 500, 'position': 'fixed', 'top': 0, 'width': entryContent.width()});
} else if ($(document).scrollTop() <= entryContent.offset().top) {
entryContent.css('padding-top', '');
entryShare.css({ 'position': '', 'z-index': '', 'width': ''});
}
}, 250);
}
});
}
<?php
//* Do NOT include the opening php tag
//* These are the buttons
<div id="social-widgets" class="social-widgets">
<div class="social-share-txt">Share:</div>
<div class="social-btn 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-btn google-widget">
<!-- Place this tag where you want the +1 button to render. -->
<div class="g-plusone" data-href="<?php echo get_permalink(); ?>" data-size="medium"></div>
</div>
<div class="social-btn twitter-widget">
<a href="https://twitter.com/share" class="twitter-share-button" data-text="<?php the_title(); ?>" data-url="<?php the_permalink(); ?>" data-via="BlogSynthesis" data-related="NetRival">Tweet</a>
</div>
<div class="social-btn 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="BlogSynthesis" data-related="NetRival">Buffer</a>
</div>
</div>
<div class="clear"></div>
/* Share bar CSS
------------------------------------------------------------ */
.social-widgets {
background: #f5f5f5;
padding: 4px;
margin-bottom: 16px;
margin-bottom: 1.6em;
height: 32px;
overflow: hidden;
}
.social-btn {
height: 28px;
vertical-align: middle;
min-width: 92px;
display: inline-block;
}
.social-share-txt {
font-weight: bold;
float: left;
margin: 0 12px;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment