There are hundreds of social media sharing plugins available in the WordPress plugin repository. But did you know that it’s super duper simple to build your own and have it integrate nicely in your own WordPress theme? Here is how:
Open up your theme’s functions.php and add this code to the bottom, right above the closing ?>
/** * Add Twitter & Facebook Sharing Icon to Posts */ function gpp_social_buttons_below($content) { global $post; $permalink = get_permalink($post->ID); $title = get_the_title(); if(!is_feed() && !is_home() && !is_page()) { $content = $content . '<div class="social-links"> <a href="http://twitter.com/share" class="twitter-share-button" data-count="none" data-url="'.$permalink.'" data-text="'.$title.'">Tweet</a> <div id="fb-root"></div><fb:like href="'.$permalink.'" layout="button_count" width="100" show_faces="false" font=""></fb:like> </div>'; } return $content; } add_filter('the_content', 'gpp_social_buttons_below');
Now open up footer.php and paste this code right below <?php wp_footer(); ?>
<script type="text/javascript" src="//platform.twitter.com/widgets.js"></script> <script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script>
Important: Implementing code snippets can be problematic unless users have basic syntax understanding. In some cases, your functions.php file might not have a closing ?>. If this is the case, just paste the PHP function above at the bottom of the functions.php file.
If you’ve done everything right, all single posts will show Twitter and Facebook sharing icons at the end of every post.
Leave a Reply