Social Media Links on homepage – within posts/post loop

I think your code should be in header.php or single.php and not index …these are the correct parts of the theme that get called with every post or page. That should fix part of the problem.

Also … With Twitter Tweet buttons, for example, you can have extra meta such as the data-URL and echo your post permalink I also use data-count as most of my permalinks are shortened and you want your click stats to follow the full post URL.

This is how I do it on my site:

<div class="wpse61568">
<a href="https://twitter.com/share" class="twitter-share-button" data-url="<?php echo get_permalink(); ?>" data-counturl=<?php echo get_permalink(); ?> data-count="horizontal" data-via="damiensaunders" rel="me">Tweet</a>
<script type="text/javascript" src="https://platform.twitter.com/widgets.js"></script></div> 

header.php with conditional tag

<?php if ( !is_single() ){ ?>
<div class="wpse61568_2">
<a href="https://twitter.com/share" class="twitter-share-button" data-url="<?php echo get_permalink(); ?>" data-counturl=<?php echo get_permalink(); ?> data-count="horizontal" data-via="damiensaunders" rel="me">Tweet</a><script type="text/javascript" src="https://platform.twitter.com/widgets.js"></script>
</div>
<?php } ?>

Leave a Comment