Created
September 28, 2017 13:03
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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