简体   繁体   English

如何将jQuery-Plugin实现到Wordpress

[英]How to implement jQuery-Plugin to Wordpress

I'm still trying to implement the jquery.contenthover.js -Plugin into wordpress, but I just can't make it work. 我还在努力实现jquery.contenthover.js -Plugin到WordPress,但我不能让它工作。

First, I have unregistered the jQuery loaded by wordpress, because the plugin needs a higher version, and registered & enqueued a higher one.. and then enqueued the plugin-js .. for this I added following to my functions.php 首先,我取消了wordpress加载的jQuery的注册,因为该插件需要更高的版本,并注册并排队了更高的版本..然后将plugin-js排队了。为此,我在我的functions.php中添加了以下内容

function init_js_scripts() {
    if (!is_admin()) {

        wp_deregister_script('jquery');
        wp_register_script('jquery','//ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js',false, '2.1.4');
        wp_enqueue_script('jquery');                        

        wp_enqueue_script('contenthover', get_template_directory_uri() . '/assets/js/jquery.contenthover.min.js', array('jquery'), false, true);


    }
}

add_action( 'init', 'init_js_scripts');

Whatever I try, it won't word :/ .. in the Firefox-Debugger the new jquery is loaded correctly but the jquery.contenthover.min.js is grayed out(?) .. how can I fix that? 无论我尝试什么,它都不会显示:/ ..在Firefox-Debugger中,新的jquery已正确加载,但jquery.contenthover.min.js变灰了(?)..我该如何解决?

EDIT: 编辑:

Thanks to Jeremy, I now know, that the Plugin-Js is loaded correctly.. but it still won't wirk.. when I extract the code into a new HTML (away from wordpress) it all works fine.. in WP it doesnt.. .. I use 多亏了杰里米,我现在才知道Plugin-Js已正确加载..但是它仍然不会变..当我将代码提取到新的HTML中(远离wordpress)时,一切正常..在WP中不....我用

<script type="text/javascript"><!--//--><![CDATA[//><!--
var $j = jQuery.noConflict();
$j(document).ready(function () {

$j('#d1').contenthover({
    effect:'slide',
    slide_speed:300,
    overlay_background:'#000',
    overlay_opacity:0.8
});
});
 //--><!]]//></script>

but with no effort. 但毫不费力。 Can someone tell me, what I do wrong? 有人可以告诉我,我做错了吗?

Firefox shows in gray scripts that are minified, like the one you include. Firefox以缩小的灰色脚本显示,就像您包含的脚本一样。 So actually, there's no problem: your script is included. 因此,实际上没有问题:脚本已包含在内。

However, you should avoid using the init action for enqueuing scripts, as wp_enqueue_scripts is a better action here. 但是,应避免将init操作用于使脚本入队,因为wp_enqueue_scripts在这里是更好的操作。 Also, you indicated that the new jQuery is a dependency for your script, so you don't need to enqueue it by yourself. 另外,您还指出了新的jQuery是脚本的依赖项,因此您无需自己排队。 I wrote a complete guide about wp_enqueue_script() if you want to learn more about it. 如果您想了解更多关于wp_enqueue_script()我写了一个完整的指南

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM