jQuery脚本在Wordpress中不起作用,尝试了多种入队方法 [英] Jquery scripts not working in Wordpress, tried multiple enqueue methods

查看:66
本文介绍了jQuery脚本在Wordpress中不起作用,尝试了多种入队方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经搜索了类似的问题,但尚未找到答案.

I've searched through similar questions, but didn't find an answer yet.

在我的Wordpress 开发站点上,我尝试使用以下jquery脚本: smoothscroll.js ,然后将动态顶部由Matt Verone(WP插件版本和手动版本)编写.都行不通.我已经在WP网站和非WP网站上成功使用了这两种工具.

On my Wordpress dev site using the Genesis framework, I tried using the following jquery scripts: smoothscroll.js and Dynamic to top by Matt Verone (both the WP plugin version and manually). Neither works. I've used both of these on WP and non-WP sites successfully.

我通过以下functions.php中的方法将smoothscroll.js和dynamic至top脚本(当手动使用时),easing.js和jquery.ui.totop.min.js入队.

I enqueued both smoothscroll.js and the dynamic to top scripts (when using it manually), easing.js and jquery.ui.totop.min.js via the following method in functions.php.

function tm_scripts()
{       
    wp_register_script( 'easing', get_stylesheet_directory_uri() . '/lib/js/easing.js', array( 'jquery' ), null, true );

    wp_register_script( 'smoothscroll', get_stylesheet_directory_uri() . '/lib/js/smoothscroll.js', array( 'jquery' ), null, true );

    wp_register_script( 'jquery.ui.totop.min', get_stylesheet_directory_uri() . '/lib/js/jquery.ui.totop.min.js', array( 'jquery' ), null, true );

    wp_register_script( 'main', get_stylesheet_directory_uri() . '/lib/js/main.js', array( 'jquery' ), null, true );

    wp_enqueue_script( 'easing' );
    wp_enqueue_script( 'smoothscroll' );
    wp_enqueue_script( 'jquery.ui.totop.min' );
    wp_enqueue_script( 'main' );
}
add_action( 'wp_enqueue_scripts', 'tm_scripts' );

当我查看代码时,它们会显示在页脚中.

They appear in the footer when I view the code.

然后,我尝试通过wp离开jquery并从CSS Tricks中使用以下jquery入队方法:

I then tried both leaving jquery to load via wp and the following jquery enqueue method from CSS Tricks:

 if (!is_admin()) add_action("wp_enqueue_scripts", "tm_jquery_enqueue", 11);
function tm_jquery_enqueue() {
   wp_deregister_script('jquery');
   wp_register_script('jquery', "http" . ($_SERVER['SERVER_PORT'] == 443 ? "s" : "") . "://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js", false, null);
   wp_enqueue_script('jquery');  
}

没有运气.我使用的唯一其他插件是Contact Form 7和Akismet.我觉得某处有冲突,只是不确定是什么.任何帮助将不胜感激.

No luck. The only other plugins I'm using are Contact Form 7 and Akismet. I feel like there is a conflict somewhere, just not sure what. Any help would be greatly appreciated.

推荐答案

CSS技巧代码也不适合我,但这是

The CSS-tricks code wasn't working for me either, but this is

add_action( 'init', 'jquery_register' );
function jquery_register() {
if ( !is_admin() ) {
wp_deregister_script( 'jquery' );
wp_register_script( 'jquery', ('http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js' ), false, null, true );
wp_enqueue_script( 'jquery' );
}
}

或其他任何jquery版本...

Or any other jquery version...

这篇关于jQuery脚本在Wordpress中不起作用,尝试了多种入队方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆