Skip to content

Instantly share code, notes, and snippets.

@robneu
Last active December 18, 2015 03:29
Show Gist options
  • Save robneu/5718586 to your computer and use it in GitHub Desktop.
Save robneu/5718586 to your computer and use it in GitHub Desktop.
Add po.st social sharing buttons to a Genesis child theme without a plugin
<?php
/**
* Adds po.st social sharing buttons
* to single posts and pages.
* Create an account at http://po.st
* to get a publisher key.
*
* @author Robert Neu
* @link http://youneedfat.com
* @copyright Copyright (c) 2013, FAT Media, LLC
* @license GPL-2.0+
*/
add_action( 'wp_enqueue_scripts', 'prefix_add_social_script' );
//* Load the required JavaScript
function prefix_add_social_script() {
//* Add as many post types as you like.
$post_types = array( 'post', );
//* Load the script only where we need it.
if ( is_singular( $post_types ) ) {
wp_enqueue_script( 'post-buttons', '//i.po.st/share/script/post-widget.js#publisherKey=yourkeyhere', array(), '1.0', true );
}
}
add_action( 'genesis_before_loop', 'prefix_add_social_buttons' );
//* Display social buttons on single posts
function prefix_add_social_buttons() {
//* Add as many post types as you like.
$post_types = array( 'post', );
//* Load the buttons only where we need them.
if ( is_singular( $post_types ) ) {
//* Add sharing buttons before the post
add_action( 'genesis_after_post_content', 'prefix_do_social_buttons' );
//* Add sharing buttons after the post
add_action( 'genesis_before_post_content', 'prefix_do_social_buttons' );
}
//* Render html for the sharing buttons
function prefix_do_social_buttons() {
echo'<div class="pw-widget addthis_toolbox pw-counter-horizontal pw-share-popups" pw:twitter-via="YourTwitterHandle">';
echo'<a class="pw-button-facebook pw-look-native"></a>';
echo'<a class="pw-button-twitter pw-look-native"></a>';
echo'<a class="pw-button-linkedin pw-look-native"></a>';
echo'<a class="pw-button-googleplus pw-look-native"></a>';
echo'<a class="pw-button-post-share"></a>';
echo'</div>';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment