[英]How to properly load/move jquery in footer of WP theme?
I'm trying to load jquery in footer of my WP theme (WP 3.8), but non of solution which I try didn't work for me. 我正在尝试将jQuery主题加载到我的WP主题(WP 3.8)的页脚中,但是我尝试的解决方案不适用于我。 I have search all over the net, but didn't find correct way to load jquery in the footer of WP theme.
我在网上搜索了所有内容,但没有找到在WP主题的页脚中加载jquery的正确方法。
This is my function.php
: 这是我的
function.php
:
if (!is_admin())
add_action("wp_enqueue_scripts", "my_jquery_enqueue", 11);
function my_jquery_enqueue() {
// Deregister the included library
wp_deregister_script('jquery');
// Register the library again from Google's CDN
wp_register_script('jquery', "http" . ($_SERVER['SERVER_PORT'] == 443 ? "s" : "") . "://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js", false, '1.10.2', true);
wp_enqueue_script('jquery');
}
And this JS is correctly loaded in the footer using this in my function.php
as well: 而且,在我的
function.php
,也可以使用此JS将其正确加载到页脚中:
/* Integrate preloader script */
wp_register_script('jPreloader', get_stylesheet_directory_uri() . '/js/loader.js', 'jquery', null, true);
wp_enqueue_script('jPreloader');
wp_enqueue_script( 'myscript', get_template_directory_uri() . '/js/scripts.min.js', array( 'jquery' ), '', true );
/*
* Register and enqueue a script that does not depend on a JavaScript library.
*/
function child_add_scripts() {
wp_register_script(
'avia',
get_stylesheet_directory_uri() . '/js/avia.js',
array('jquery'),
'1.1',
true
);
wp_register_script(
'bottom',
get_stylesheet_directory_uri() . '/js/bottom.js',
array('jquery'),
null,
true
);
wp_enqueue_script('avia');
wp_enqueue_script('bottom');
}
// Run this function during the wp_enqueue_scripts action
add_action( 'wp_enqueue_scripts', 'child_add_scripts' );
Don't know why jQuery isn't loaded in the footer of my WP theme, what I'm doing wrong? 不知道为什么未在WP主题的页脚中加载jQuery,我在做什么错?
Try this: 尝试这个:
if (!is_admin())
add_action("wp_enqueue_scripts", "my_jquery_enqueue", 11);
function my_jquery_enqueue() {
// Deregister the included library
wp_deregister_script('jquery');
// Register the library again from Google's CDN
$googleScript = 'http'. ($_SERVER['SERVER_PORT'] == 443 ? "s" : "") . '://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js';
wp_register_script('jquery', $googleScript, false, '1.10.2', true);
wp_enqueue_script('jquery');
}
I have use this function to move jquery to footer: 我已经使用此功能将jQuery移动到页脚:
function custom_clean_head() {
remove_action('wp_head', 'wp_print_scripts');
remove_action('wp_head', 'wp_print_head_scripts', 9);
remove_action('wp_head', 'wp_enqueue_scripts', 1);
add_action('wp_footer', 'wp_print_scripts', 5);
add_action('wp_footer', 'wp_enqueue_scripts', 5);
add_action('wp_footer', 'wp_print_head_scripts', 5);
}
add_action( 'wp_enqueue_scripts', 'custom_clean_head' );
But, I need solution for my preloader which I have on my test site here: http://dev.bogosavljev.com/ 但是,我需要在我的测试站点上的预加载器解决方案: http : //dev.bogosavljev.com/
Can somebody take a look, and tell me what i have done wrong? 有人可以看看,然后告诉我我做错了什么吗?
Problem is that content on page is shown for a sec., and then my preloader (animated letter B) is shown, and after that with fade effect, it's shown page. 问题是页面上的内容显示了几秒钟,然后显示了我的预加载器(动画字母B),然后带有淡入淡出效果,显示了页面。
How to show first preloader (/js/loader.js), and then the page? 如何先显示预加载器(/js/loader.js),然后显示页面? For reference I have use Adham site which have same effect - http://www.adhamdannaway.com/
作为参考,我使用了具有相同效果的Adham网站-http: //www.adhamdannaway.com/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.