Last active
December 15, 2015 16:59
-
-
Save gregrickaby/5292781 to your computer and use it in GitHub Desktop.
Add social media icons in Genesis without a plug-in
This file contains hidden or 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
<?php | |
// Do NOT include the opening php tag | |
// pre-html5 hook add_action( 'genesis_before_post_content', 'child_social_media_icons', 5 ); | |
add_action( 'genesis_before_entry_content', 'child_social_media_icons', 5 ); | |
/** | |
* Social Media Icons without a plugin | |
* | |
* Use conditional tags to place on desired posts and pages. | |
* | |
* @author Greg Rickaby | |
* @since 1.0.0 | |
* @link http://codex.wordpress.org/Conditional_Tags | |
* @return html official social media icons | |
*/ | |
function child_social_media_icons() { | |
// Conditinal Tag | |
// Display on single posts only | |
if ( is_single() ) { ?> | |
<div class="social-media-icons"> | |
<div class="facebook-button"> | |
<div class="fb-like" data-href="<?php the_permalink(); ?>" data-layout="button_count" data-action="like" data-show-faces="false" data-share="false"></div> | |
</div> | |
<div class="twitter-button"> | |
<a href="https://twitter.com/share" class="twitter-share-button" data-url="<?php the_permalink(); ?>" data-via="YOUR-TWITTER-USERNAME-HERE" data-lang="en">Tweet</a> | |
</div> | |
<div class="gplus-button"> | |
<div class="g-plusone" data-href="<?php the_permalink(); ?>"></div> | |
</div> | |
<div class="pinterest-button"> | |
<a href="//pinterest.com/pin/create/button/?url=<?php the_permalink(); ?>&media=<?php echo genesis_get_image( array( 'format' => 'url' ) ); ?>&description=<?php the_title(); ?>" data-pin-do="buttonPin" data-pin-config="beside"><img src="//assets.pinterest.com/images/pidgets/pin_it_button.png" /></a> | |
</div> | |
<div class="pocket-button"> | |
<a data-pocket-label="pocket" data-pocket-count="none" class="pocket-btn" data-lang="en"></a> | |
</div> | |
<div class="linkedin-button"> | |
<script type="IN/Share" data-url="<?php the_permalink(); ?>" data-counter="right"></script> | |
</div> | |
<div class="stumbleupon-button"> | |
<su:badge layout="1" location="<?php the_permalink(); ?>"></su:badge> | |
</div> | |
<div class="reddit-button"> | |
<script async src="//www.reddit.com/static/button/button1.js"></script> | |
</div> | |
</div><!-- .social-media-icons --> | |
<?php } | |
} | |
add_action( 'wp_footer', 'child_social_media_scripts', 99 ); | |
/** | |
* Social Media Javasripts | |
* | |
* @author Greg Rickaby | |
* @since 1.0.0 | |
* @return html javascript to instantiate buttons | |
*/ | |
function child_social_media_scripts() { ?> | |
<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&appId=227147837348982";fjs.parentNode.insertBefore(js,fjs);}(document,'script','facebook-jssdk'));</script> | |
<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>(function(){var po=document.createElement('script');po.type='text/javascript';po.async=true;po.src='//apis.google.com/js/platform.js';var s=document.getElementsByTagName('script')[0];s.parentNode.insertBefore(po,s);})();</script> | |
<script>(function(){var li=document.createElement('script');li.type='text/javascript';li.async=true;li.src=('https:'==document.location.protocol ? 'https:' : 'http:') + '//platform.stumbleupon.com/1/widgets.js';var s=document.getElementsByTagName('script')[0];s.parentNode.insertBefore(li,s);})();</script> | |
<script>!function(d,i){if(!d.getElementById(i)){var j=d.createElement("script");j.id=i;j.src="//widgets.getpocket.com/v1/j/btn.js?v=1";var w=d.getElementById(i);d.body.appendChild(j);}}(document,"pocket-btn-js");</script> | |
<script async src="//assets.pinterest.com/js/pinit.js"></script> | |
<script async src="//platform.linkedin.com/in.js">lang: en_US</script> | |
<?php } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment