admin管理员组文章数量:1022553
My plugin uses the following to enqueue script in jQuery dependency:
wp_enqueue_script( $plugin_short_slug, plugins_url() . '/' . $plugin_slug . '/js/' . $plugin_slug . '.js', '', array('jquery'), '', true);
If I use it on child theme where I dequeue default WordPress jQuery and load jQuery from CDN in footer, both jQuery and my script land in footer and it works correctly.
Unfortunately when I use plugin on default theme, where default WordPress jQuery is loaded in header, $in_footer
is ignored, script appears in header after jQuery and doesn't work despite no errors in console.
I wouldn't like to replace default jQuery or even move it to the footer, because it can break other things for users.
My script is the following, phpVars
is properly passed in localized script, above in generated HTML:
var timeout;
jQuery('div.woocommerce').on('change', '.qty', function(){
if (timeout != undefined) clearTimeout(timeout);
timeout = setTimeout(function() {
jQuery('[name="update_cart"]').trigger('click');
}, phpVars.acau_update_delay );
});
EDIT:
Apparently jQuery dependence makes no difference, if I specify an empty array instead, plugin script is still loaded in header below jQuery and doesn't work, this time only with version parameter instead of both version and jQuery ?ver%5B0%5D=jquery
.
My plugin uses the following to enqueue script in jQuery dependency:
wp_enqueue_script( $plugin_short_slug, plugins_url() . '/' . $plugin_slug . '/js/' . $plugin_slug . '.js', '', array('jquery'), '', true);
If I use it on child theme where I dequeue default WordPress jQuery and load jQuery from CDN in footer, both jQuery and my script land in footer and it works correctly.
Unfortunately when I use plugin on default theme, where default WordPress jQuery is loaded in header, $in_footer
is ignored, script appears in header after jQuery and doesn't work despite no errors in console.
I wouldn't like to replace default jQuery or even move it to the footer, because it can break other things for users.
My script is the following, phpVars
is properly passed in localized script, above in generated HTML:
var timeout;
jQuery('div.woocommerce').on('change', '.qty', function(){
if (timeout != undefined) clearTimeout(timeout);
timeout = setTimeout(function() {
jQuery('[name="update_cart"]').trigger('click');
}, phpVars.acau_update_delay );
});
EDIT:
Apparently jQuery dependence makes no difference, if I specify an empty array instead, plugin script is still loaded in header below jQuery and doesn't work, this time only with version parameter instead of both version and jQuery ?ver%5B0%5D=jquery
.
1 Answer
Reset to default 0It's all about poor typo, I put one extra parameter ''
before dependency parameter:
wp_enqueue_script( $plugin_short_slug, plugins_url() . '/' . $plugin_slug . '/js/' . $plugin_slug . '.js', '', array('jquery'), '', true);
should be:
wp_enqueue_script( $plugin_short_slug, plugins_url() . '/' . $plugin_slug . '/js/' . $plugin_slug . '.js', array('jquery'), '', true);
Now my script properly loads in footer.
My plugin uses the following to enqueue script in jQuery dependency:
wp_enqueue_script( $plugin_short_slug, plugins_url() . '/' . $plugin_slug . '/js/' . $plugin_slug . '.js', '', array('jquery'), '', true);
If I use it on child theme where I dequeue default WordPress jQuery and load jQuery from CDN in footer, both jQuery and my script land in footer and it works correctly.
Unfortunately when I use plugin on default theme, where default WordPress jQuery is loaded in header, $in_footer
is ignored, script appears in header after jQuery and doesn't work despite no errors in console.
I wouldn't like to replace default jQuery or even move it to the footer, because it can break other things for users.
My script is the following, phpVars
is properly passed in localized script, above in generated HTML:
var timeout;
jQuery('div.woocommerce').on('change', '.qty', function(){
if (timeout != undefined) clearTimeout(timeout);
timeout = setTimeout(function() {
jQuery('[name="update_cart"]').trigger('click');
}, phpVars.acau_update_delay );
});
EDIT:
Apparently jQuery dependence makes no difference, if I specify an empty array instead, plugin script is still loaded in header below jQuery and doesn't work, this time only with version parameter instead of both version and jQuery ?ver%5B0%5D=jquery
.
My plugin uses the following to enqueue script in jQuery dependency:
wp_enqueue_script( $plugin_short_slug, plugins_url() . '/' . $plugin_slug . '/js/' . $plugin_slug . '.js', '', array('jquery'), '', true);
If I use it on child theme where I dequeue default WordPress jQuery and load jQuery from CDN in footer, both jQuery and my script land in footer and it works correctly.
Unfortunately when I use plugin on default theme, where default WordPress jQuery is loaded in header, $in_footer
is ignored, script appears in header after jQuery and doesn't work despite no errors in console.
I wouldn't like to replace default jQuery or even move it to the footer, because it can break other things for users.
My script is the following, phpVars
is properly passed in localized script, above in generated HTML:
var timeout;
jQuery('div.woocommerce').on('change', '.qty', function(){
if (timeout != undefined) clearTimeout(timeout);
timeout = setTimeout(function() {
jQuery('[name="update_cart"]').trigger('click');
}, phpVars.acau_update_delay );
});
EDIT:
Apparently jQuery dependence makes no difference, if I specify an empty array instead, plugin script is still loaded in header below jQuery and doesn't work, this time only with version parameter instead of both version and jQuery ?ver%5B0%5D=jquery
.
1 Answer
Reset to default 0It's all about poor typo, I put one extra parameter ''
before dependency parameter:
wp_enqueue_script( $plugin_short_slug, plugins_url() . '/' . $plugin_slug . '/js/' . $plugin_slug . '.js', '', array('jquery'), '', true);
should be:
wp_enqueue_script( $plugin_short_slug, plugins_url() . '/' . $plugin_slug . '/js/' . $plugin_slug . '.js', array('jquery'), '', true);
Now my script properly loads in footer.
本文标签: plugin developmentjQuery dependent script ignores infooter bool and doesn39t work in header
版权声明:本文标题:plugin development - jQuery dependent script ignores $in_footer bool and doesn't work in header 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745525446a2154503.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论