Created
December 7, 2011 21:55
-
-
Save zachbrowne/1444875 to your computer and use it in GitHub Desktop.
Add Fast Loading Social Sharing to WordPress Thesis Theme
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
/* .clear rules may be removed if you have them already in your custom.css */ | |
.clear { | |
clear:both; | |
} | |
/* share buttons */ | |
#social_buttons { | |
clear:both; | |
margin-bottom:1.5em; | |
} | |
.custom_share_button_box { | |
display:block; | |
float:right; | |
width:110px; | |
} | |
.facebook_button.custom_share_button_box { | |
width:150px; | |
} | |
.google_one_button.custom_share_button_box { | |
width:90px; | |
} |
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 | |
/* add thumbnail support to thesis */ | |
if(!function_exists('get_post_thumbnail_id') && function_exists('add_theme_support')) { | |
add_theme_support('post-thumbnails'); | |
} | |
/* social sharing */ | |
//twitter data-via in user's profile | |
function custom_add_twitter_via($contact_methods) { | |
$contact_methods['tweet_via'] = __('Tweet your content via : @','custom_lang'); | |
return $contact_methods ; | |
} | |
add_filter('user_contactmethods','custom_add_twitter_via',90,1); | |
//fb protocol extension | |
if(!function_exists('fb_protocol')) { | |
function fb_protocol($defaults) { | |
return $defaults . ' xmlns:og="http://ogp.me/ns#" xmlns:fb="http://www.facebook.com/2008/fbml" '; | |
} | |
add_filter('language_attributes','fb_protocol',10,1); | |
} | |
//output share buttons | |
function custom_share_buttons() { | |
if(is_singular()) { | |
global $post; | |
$user = new WP_User($post->post_author); | |
} | |
elseif(is_author()) { | |
global $wp_query ; | |
$user = new WP_User($wp_query->query_vars['author']); | |
} | |
else | |
$user = new WP_User(1); | |
$data_via = ($user->tweet_via != '') ? 'data-via="'. $user->tweet_via .'"' : '' ; | |
echo ' | |
<div id="social_buttons"> | |
<div class="facebook_button custom_share_button_box"> | |
<div id="fb-root"></div> | |
<fb:like href="" send="true" layout="button_count" width="150" show_faces="false" action="like" font=""></fb:like> | |
</div> | |
<div class="twitter_button custom_share_button_box"> | |
<a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" '. $data_via .'>Tweet</a> | |
</div> | |
<div class="linkedin_button custom_share_button_box"> | |
<script type="IN/Share" data-counter="right"></script> | |
</div> | |
<div class="google_one_button custom_share_button_box"> | |
<g:plusone size="medium"></g:plusone> | |
</div> | |
<div class="clear"></div> | |
</div>' ; | |
} | |
//output social share scripts | |
function custom_add_share_scripts() { | |
echo ' | |
<script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script> | |
<script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script> | |
<script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script> | |
<script src="http://platform.linkedin.com/in.js" type="text/javascript"></script>' ; | |
} | |
//social share "decider" in <head> section | |
function custom_add_social_share() { | |
$hook = (is_singular() && !is_singular('page')) ? 'thesis_hook_before_post' : 'thesis_hook_after_content' ; | |
add_action($hook,'custom_share_buttons',1,0); | |
if($hook == 'thesis_hook_after_content') { | |
add_action('thesis_hook_after_content',create_function('','echo "<div class=\"clear\"></div>";'),0,0); | |
add_action('thesis_hook_after_content',create_function('','echo "<div class=\"clear\"></div>";'),2,0); | |
} | |
if(is_singular()) { | |
global $post; | |
if(get_post_meta($post->ID, 'thesis_post_image', true) != '') { | |
if(!strstr(get_post_meta($post->ID, 'thesis_post_image', true), get_bloginfo('url'))) { | |
$image = THESIS_SCRIPTS_FOLDER . '/thumb.php?src=' . urlencode(get_post_meta($post->ID, 'thesis_post_image', true)) . '&w=125&h=125&zc=1&q=100'; | |
} | |
else | |
$image = get_post_meta($post->ID, 'thesis_post_image', true); | |
echo '<meta content="'.$image.'" property="og:image" />' . "\n" ; | |
} | |
else { | |
$image_object = get_post(get_post_thumbnail_id($post->ID)); | |
if(!is_wp_error($image_object) && $image_object != '') { | |
$image = wp_get_attachment_image_src(get_post_thumbnail_id($parent_id),'thumbnail',false); | |
echo '<meta content="'. $image[0] .'" property="og:image" />' . "\n" ; | |
} | |
} | |
} | |
add_action('thesis_hook_after_html','custom_add_share_scripts'); | |
} | |
add_action('wp_head','custom_add_social_share'); | |
/* end social sharing */ | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment