How to quickly add the Tweet Button to your TwentyTen Template in WordPress

Just added the new Tweet Button to this WordPress blog that uses the standard TwentyTen template. It’s really quick and simple…

Firstly, I added this to a child of TwentyTen, which makes it much easier to configure the template and prevents me losing functionality when it updates. But in any case it is really just a matter of adding this to your functions.php file in your Appearance->Editor.

Just paste in this code and save it…


function add_pre_content($content) {
	if(!is_feed() && !is_home()) {
		$content = '<a href="http://twitter.com/share" class="twitter-share-button" data-count="vertical" data-url="'.get_permalink().'" data-via="shawndm">Tweet</a>
			<script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>'.$content;
	}
	return $content;
}
add_filter('the_content', 'add_pre_content');

Which will require just one change, change my “shawndm” to your Twitter account name and that’s it – it will appear just before the content and just after your title.

This entry was posted in Miscellaneous. Bookmark the permalink.

4 Responses to How to quickly add the Tweet Button to your TwentyTen Template in WordPress

Leave a Reply

Your email address will not be published. Required fields are marked *