Pastebin launched a little side project called HostCabi.net, check it out ;-)Don't like ads? PRO users don't see any ads ;-)

addThis Pinterest WordPress filter

By: bradtrivers on Feb 27th, 2012  |  syntax: PHP  |  size: 2.09 KB  |  hits: 165  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. add_filter( 'the_content', 'sharingButtons_addThis', 100 );
  2. // Put AddThis buttons at the bottom of every post.
  3. function sharingButtons_addThis( $content ) {
  4.   global $post;
  5.   if(isset($post)) {
  6.     //Set Pinterest image using "Get The Image" plugin by Justin Tadlock
  7.     if ( function_exists( 'get_the_image' ) ) {
  8.       $getTheImageOptions = array(
  9.         'meta_key' => array( 'Thumbnail', 'thumbnail' ),
  10.         'post_id' => $post->ID,
  11.         'attachment' => true,
  12.         'the_post_thumbnail' => true,
  13.         'size' => 'large',
  14.         'default_image' => false,
  15.         'order_of_image' => 1,
  16.         'link_to_post' => true,
  17.         'image_class' => false,
  18.         'image_scan' => false,
  19.         'width' => false,
  20.         'height' => false,
  21.         'format' => 'array',
  22.         'meta_key_save' => false,
  23.         'callback' => null,
  24.         'cache' => true,
  25.         'echo' => false
  26.       );
  27.       $pinterest = get_the_image($getTheImageOptions);
  28.       $pinterestURL = $pinterest['url'];
  29.     } else {
  30.       $pinterestURL = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
  31.     }
  32.   } else {
  33.     $pinterestURL = "";
  34.   }
  35.  
  36.   $currentURL = 'http://'.$_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
  37.  
  38.   $content .= '         <!-- AddThis Button BEGIN -->';
  39.   $content .= '    <div class="addthis_toolbox addthis_default_style ">';
  40.   $content .= '    <a class="addthis_button_facebook_like" fb:like:layout="button_count"></a>';
  41.   if(!empty($pinterestURL)) {
  42.     $content .= '    <a class="addthis_button_pinterest" pi:pinit:url="'. $currentURL .'" pi:pinit:media="'. $pinterestURL .'" pi:pinit:layout="horizontal"></a>';
  43.   }
  44.   $content .= '    <a class="addthis_button_tweet"></a>';
  45.   $content .= '    <a class="addthis_button_google_plusone" g:plusone:size="medium"></a>';
  46.   $content .= '    <a class="addthis_counter addthis_pill_style"></a> ';
  47.   $content .= '    </div>';
  48.   $content .= '    <script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#pubid=btrivers"></script>';
  49.   $content .= '    <!-- AddThis Button END -->    ';
  50.  
  51.   // Returns the content.
  52.   return $content;
  53. }