Add Social Share Buttons To The WordPress Post Management Screen

Share Posts Management Screen

One of the things that’s difficult with blogs where you pump out a lot of content is having an overview of how many shares your posts are getting on Facebook, Twitter, StumbleUpon and other networks without visiting each post individually to check out the share buttons.

Sure this can be accomplished via analytics but depending on the analytics platform  you use the results can be anywhere up to 24 hours behind.

Earlier today I knocked up this little piece of code that can either be used as plugin or dropped into your functions.php which will add share buttons in a column on the post management screen so that you can see how your posts are doing and share directly from management screen if you want to.

I’m sure there are more elegant ways to do this, possibly using wp_enque_script but as the script only runs on edit.php and Facebook and other networks have a nasty habit of changing their code without much warning, I thought this would be simpler.

Comments, suggestions and improvements welcome.

add_action( 'admin_head-edit.php', 'add_socialm_head_script' );

function add_socialm_head_script() { ?>

<script type="text/javascript">
(function() {
var li = document.createElement('script'); li.type = 'text/javascript'; li.async = true;
li.src = window.location.protocol + '//';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(li, s);

<link href="" rel="publisher" /><script type="text/javascript">
window.___gcfg = {lang: 'en'};
{var po = document.createElement("script");
po.type = "text/javascript"; po.async = true;po.src = "";
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(po, s);

<?php }

if ( !function_exists('AddShareColumn')) {

function AddShareColumn($cols) {
$cols['sharebuttons'] = __('Share');
return $cols;
function AddShareLink($column_name, $post_id) {

if ( 'sharebuttons' == $column_name ) {
echo '<su:badge layout="1" location="'.get_permalink($post_id).'"></su:badge><br />';

echo '//'.get_permalink().'&send=false&layout=button_count&width=90&amp;show_faces=false&action=like&colorscheme=light&font&height=21&appId=APPID<br />';

echo '<a href="" class="twitter-share-button"
data-url="'.get_permalink($post_id).'" data-text="'.get_the_title().'"
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);;js.src="//"
;fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script><br />';

echo '<g:plusone size="small" href="'.get_permalink($post_id).'"></g:plusone>';

// for posts
add_filter( 'manage_posts_columns', 'AddShareColumn' );
add_action( 'manage_posts_custom_column', 'AddShareLink', 10, 2 );
// for pages
add_filter( 'manage_pages_columns', 'AddShareColumn' );
add_action( 'manage_pages_custom_column', 'AddShareLink, 10, 2 );