This is how to change the default display behaviour of the Jetpack plugin’s sharing buttons feature.

I’ve been using Jetpack to provide sharing buttons to Twitter, Facebook and the like on my personal site and was having an issue with where they were being positioned in a post. Because Jetpack adds the button code onto the end of the post content using a filter, they weren’t playing nicely with the elements in my theme that came after the post content. This was particularly noticeable when display the quote post format as the buttons were getting all wrapped up in a blockquote tag.

So I searched for a solution and eventually ended up with some code that strips out the buttons from the post content and then adds them back into the theme in the place where you want them displayed. Although I’ve not been using it, this code also does the same for Jetpack’s ‘like’ feature.

In your theme’s functions.php file add the following:

function jptweak_remove_share() {
if ( function_exists( 'sharing_display' ) ) remove_filter( 'the_content', 'sharing_display',19 );
if ( function_exists( 'sharing_display' ) ) remove_filter( 'the_excerpt', 'sharing_display',19 );
if ( class_exists( 'Jetpack_Likes' ) ) {
remove_filter( 'the_content', array( Jetpack_Likes::init(), 'post_likes' ), 30, 1 );
add_action( 'loop_start', 'jptweak_remove_share' );

Then where you want the sharing and like buttons to be displayed in your template files add this:

if ( function_exists( 'sharing_display' ) ) {
sharing_display( '', true );

if ( class_exists( 'Jetpack_Likes' ) ) {
$custom_likes = new Jetpack_Likes;
echo $custom_likes->post_likes( '' );

I actually wrapped the last bit of code in its own function and called that in the template for neatness sake.

The various if statements should ensure that everything works smoothly whether or not you have the particular Jetpack feature switched on or not.

The sources for this code are: