-
-
Save About2git/cbac3fa04332d163ad42 to your computer and use it in GitHub Desktop.
How to add Facebook, Google+ and Twitter sharing buttons without using a plugin in Genesis
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
| //* Add Facebook, Google+ and Twitter sharing buttons after header | |
| add_action( 'get_header', 'facebook_share_btn_sdk' ); | |
| function facebook_share_btn_sdk() { | |
| echo '<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/sdk.js#xfbml=1&appId=357648750922513&version=v2.0"; | |
| fjs.parentNode.insertBefore(js, fjs); | |
| }(document, \'script\', \'facebook-jssdk\'));</script>'; | |
| } | |
| add_action( 'wp_footer', 'google_share_init' ); | |
| function google_share_init() { | |
| echo '<script src="https://apis.google.com/js/platform.js" async defer></script>'; | |
| } | |
| add_action( 'genesis_after_header', 'facebook_share_btn' ); | |
| function facebook_share_btn() { | |
| echo '<div class="social-media-sharing"><div class="wrap"> | |
| <div class="fb-share-button social-share-btn" data-layout="button_count"></div> | |
| <div class="social-share-btn"><div class="g-plus" data-action="share" data-annotation="bubble"></div></div> | |
| <div class="social-share-btn"><a href="https://twitter.com/share" class="twitter-share-button" data-via="srikat">Tweet</a> | |
| <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?\'http\':\'https\';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+\'://platform.twitter.com/widgets.js\';fjs.parentNode.insertBefore(js,fjs);}}(document, \'script\', \'twitter-wjs\');</script> | |
| </div> | |
| </div></div>'; | |
| } |
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
| /* Facebook, Google+ and Twitter sharing buttons | |
| --------------------------------------------------- */ | |
| .social-media-sharing { | |
| margin-top: 40px; | |
| } | |
| .social-share-btn { | |
| margin-right: 20px; | |
| display: inline-block; | |
| float: left; | |
| } | |
| .social-share-btn:last-child { | |
| margin-right: 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment