AdmiralCrunch
AdmiralCrunch

Reputation: 151

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.

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

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?

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

<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?

Upvotes: 0

Views: 95

Answers (1)

Jeremy
Jeremy

Reputation: 548

Firefox shows in gray scripts that are minified, like the one you include. 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. Also, you indicated that the new jQuery is a dependency for your script, so you don't need to enqueue it by yourself. I wrote a complete guide about wp_enqueue_script() if you want to learn more about it.

Upvotes: 1

Related Questions