0

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?

8
  • Where is your script tag on your page? It must appear after the other scripts are included. To be sure that it's the case, you should write this script in an external file and enqueue it the same you you enqueued the library (be sure you indicate contenthover as a dependency). Commented Nov 11, 2015 at 15:24
  • the jQuery-2.1.4 is in the header as the fist js that is loaded.. the contenthover.js and the contenthoverInit ( here I have put the initialisation-code for the DIV) are at the bottom of the sourcecode.. close to the </body>-tag Commented Nov 12, 2015 at 9:38
  • Do you have any error in your JavaScript console? Commented Nov 12, 2015 at 9:40
  • no, absolutely nothing :/ Commented Nov 12, 2015 at 15:11
  • Are you sure that #d1 exists? Also make sure the function is called, with console.log() for example. Commented Nov 12, 2015 at 15:23

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.