admin管理员组文章数量:1130349
I want to move jquery.js from header to footer. I have tried following code:
//Remove jQuery Default
function replace_jquery() {
if (!is_admin()) {
wp_deregister_script('jquery');
}
}
add_action('init', 'replace_jquery');
//Load on Footer
add_action('wp_footer', 'jquery_code');
function jquery_code(){
?>
<script type='text/javascript' src='.js'></script>
<?php
};
The issue is that If I run first piece of above code, js files of my theme are removed with jquery.js. Because theme's static js files is calling via array( 'jquery' ) attributes.
I just want to move jquery only from header to footer.
NOTE: I have tried other suggestions on Stackexchange but none of them didn't work on my blog. (Such us: Enqueue core jQuery in the footer?)
How can I do it?
I want to move jquery.js from header to footer. I have tried following code:
//Remove jQuery Default
function replace_jquery() {
if (!is_admin()) {
wp_deregister_script('jquery');
}
}
add_action('init', 'replace_jquery');
//Load on Footer
add_action('wp_footer', 'jquery_code');
function jquery_code(){
?>
<script type='text/javascript' src='https://example/wp-includes/js/jquery/jquery.js'></script>
<?php
};
The issue is that If I run first piece of above code, js files of my theme are removed with jquery.js. Because theme's static js files is calling via array( 'jquery' ) attributes.
I just want to move jquery only from header to footer.
NOTE: I have tried other suggestions on Stackexchange but none of them didn't work on my blog. (Such us: Enqueue core jQuery in the footer?)
How can I do it?
Share Improve this question asked Jan 10, 2019 at 14:48 Serdar KoçakSerdar Koçak 522 silver badges7 bronze badges1 Answer
Reset to default 0When you deregister jQuery, you have to register it again. Try this code
UPDATE: You have to deregister jQuery first (first part of your code), so the final code should be:
//Load on Footer
add_action('wp_enqueue_scripts', 'register_jquery');
function register_jquery() {
wp_deregister_script('jquery'); // remove original jQuery
wp_register_script( // add custom jQuery in footer
'jquery',
'https://ajax.googleapis/ajax/libs/jquery/3.1.1/jquery.min.js',
array(), // dependencies
null, // version
true); // load in footer?
wp_enqueue_script('jquery');
}
But it's NOT RECOMMENDED to load custom jquery in wordpress.
I want to move jquery.js from header to footer. I have tried following code:
//Remove jQuery Default
function replace_jquery() {
if (!is_admin()) {
wp_deregister_script('jquery');
}
}
add_action('init', 'replace_jquery');
//Load on Footer
add_action('wp_footer', 'jquery_code');
function jquery_code(){
?>
<script type='text/javascript' src='.js'></script>
<?php
};
The issue is that If I run first piece of above code, js files of my theme are removed with jquery.js. Because theme's static js files is calling via array( 'jquery' ) attributes.
I just want to move jquery only from header to footer.
NOTE: I have tried other suggestions on Stackexchange but none of them didn't work on my blog. (Such us: Enqueue core jQuery in the footer?)
How can I do it?
I want to move jquery.js from header to footer. I have tried following code:
//Remove jQuery Default
function replace_jquery() {
if (!is_admin()) {
wp_deregister_script('jquery');
}
}
add_action('init', 'replace_jquery');
//Load on Footer
add_action('wp_footer', 'jquery_code');
function jquery_code(){
?>
<script type='text/javascript' src='https://example/wp-includes/js/jquery/jquery.js'></script>
<?php
};
The issue is that If I run first piece of above code, js files of my theme are removed with jquery.js. Because theme's static js files is calling via array( 'jquery' ) attributes.
I just want to move jquery only from header to footer.
NOTE: I have tried other suggestions on Stackexchange but none of them didn't work on my blog. (Such us: Enqueue core jQuery in the footer?)
How can I do it?
Share Improve this question asked Jan 10, 2019 at 14:48 Serdar KoçakSerdar Koçak 522 silver badges7 bronze badges1 Answer
Reset to default 0When you deregister jQuery, you have to register it again. Try this code
UPDATE: You have to deregister jQuery first (first part of your code), so the final code should be:
//Load on Footer
add_action('wp_enqueue_scripts', 'register_jquery');
function register_jquery() {
wp_deregister_script('jquery'); // remove original jQuery
wp_register_script( // add custom jQuery in footer
'jquery',
'https://ajax.googleapis/ajax/libs/jquery/3.1.1/jquery.min.js',
array(), // dependencies
null, // version
true); // load in footer?
wp_enqueue_script('jquery');
}
But it's NOT RECOMMENDED to load custom jquery in wordpress.
本文标签: phpMove Jqueryjs to Footer
版权声明:本文标题:php - Move Jquery.js to Footer 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749024947a2304957.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论