Skip to content

Instantly share code, notes, and snippets.

@lgladdy
Created September 28, 2017 13:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lgladdy/993b17a1360fdfb430e1e3e735843a84 to your computer and use it in GitHub Desktop.
Save lgladdy/993b17a1360fdfb430e1e3e735843a84 to your computer and use it in GitHub Desktop.
If you're using a build process to manage compilation of multiple javascript files on WordPress and getting errors from jetpack's sharing JS because jQuery isn't ready yet, you can use the following to wrap it in a handler which only inits after the DOM is ready
add_action('wp_footer', 'wrap_jetpack_sharing', 18);
function wrap_jetpack_sharing() {
global $wp_scripts;
$a = $wp_scripts->get_data('sharing-js','after');
$data = 'document.addEventListener( "DOMContentLoaded", function() { ';
$data .= implode("\n", $a);
$data .= ' }, false );';
$script[] = $data;
$wp_scripts->add_data('sharing-js', 'after', $script);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment