Closed ronalfy closed 9 years ago
BTW, I am using the Google Pagespeed Mod, but I disabled it for testing and have concluded that Google Pagespeed is not a factor in this case.
I think it is because Jetpack is adding footer scripts by adding sharing_add_footer()
to wp_footer
action call during the_content
which then calls the relevant wp_enqueue_script()
during wp_footer
.
Will try to debug this locally.
Basically sharing_add_footer()
relies on jQuery being available in the header because it prints inline JS. A quick fix would be to move
add_action( 'wp_footer', 'sharing_add_footer' );
to something later (after wp_print_footer_scripts
which is priority 20 during wp_footer
)
remove_action( 'wp_footer', 'sharing_add_footer' );
add_action( 'wp_footer', 'sharing_add_footer', 25 );
I just verified that the following snipped does indeed solve the problem:
add_action( 'wp_footer', 'fix_jetpack_sharing_js', 5 );
function fix_jetpack_sharing_js() {
remove_action( 'wp_footer', 'sharing_add_footer' );
add_action( 'wp_footer', 'sharing_add_footer', 25 );
}
Thanks Kaspars! This is a good fix. It would be nice if there was a way to add inline script dependencies the way styles work. I searched trac and haven't really found anything.
That whole Jetpack section needs to be rewritten. Your code got me partially there. The actual counts aren't working with the code you supplied because the sharing-js handle isn't able to run.
I added an extra action to fix the problem. Thanks for the help Kaspars!
add_action( 'wp_footer', 'fix_jetpack_sharing_js', 5 );
add_action( 'wp_footer', 'fix_jetpack_sharing_enqueue', 24 );
function fix_jetpack_sharing_enqueue() {
if ( wp_script_is( 'jquery', 'done' ) ) {
wp_print_scripts( 'sharing-js' );
}
}
function fix_jetpack_sharing_js() {
remove_action( 'wp_footer', 'sharing_add_footer' );
add_action( 'wp_footer', 'sharing_add_footer', 25 );
}
This would all be solved if Jetpack would properly enqueue their dependencies :D - I added a comment to your Jetpack issue that may help solve it, but I want to get a blessing before I take the time with a pull request.
Sorry, grr, the above code worked, but I have no idea why. I'll dig more into this later. Too tired atm :D
Kaspars, sorry to keep spamming you :)
This code works!
I'll do my own investigating of this, but minit doesn't seem to play well with Jetpack's sharing buttons. I keep getting jQuery undefined errors, but elsewhere the script is working fine.
When I have the time, I'll investigate the problem and do a pull request if the error is on this side.
Here's a sample post if you want to see the console errors: http://www.ronalfy.com/when-the-wife-gets-a-tattoo-and-doesnt-tell-you/