Moving Jetpack Sharing Buttons

I’m working on a new WordPress theme (for this site, and it’ll be released for download once complete). The theme is deeply integrated with Jetpack, and one of the things I wanted to do was have the Jetpack Sharing buttons appear in a location other than the very end of the content. Normally they are applied as a filter on the_content, so they just appear right at the end. I wanted to relocate them into a different location, and it turns out that’s really easy to do with the power of jQuery.

jQuery( document ).ready( function( $ ) {
	// Relocate Jetpack sharing buttons down into the comments form
	jQuery( '#sharing' ).html( jQuery( '.sharedaddy' ).detach() );
} );

The #sharing selector is just the DOM location where I want to move the buttons to, and the .sharedaddy one is the container that Jetpack places its buttons in normally. We just detach it from the normal position and then dump it into the new location exactly as it was.

Closing a Window in JavaScript

If you’re having trouble closing a window using JavaScript, this might help. I’ve had this problem sometimes in Chrome in particular when I open a window, then follow through a bunch of redirects or something. It seems to lose track of the fact that I “control” this window object, so it doesn’t allow me to close it. This fixes that:

window.open('', '_self', '');
window.close();

Basically it reopens the window on itself, then immediately closes itself. Neat. Haven’t had any problems with it not working in other browsers, but I also haven’t super-widely tested it.