sara
sara

Reputation: 41

Need help adding some JavaScript code into my wordpress theme

Hello I have this script here and I need to put that in my current wordpress theme, but I am confused with the enqueue part. I know I have to save the hoverintent javascript in my themes library, do I also save the functions javascript in my themes library? Sorry if I did not clarify enough, comment if this is confusing please!

jsfiddle.net/ctLevz8L/59/

Upvotes: 2

Views: 139

Answers (1)

cpilko
cpilko

Reputation: 11852

Take the javascript from your fiddle and save that to wp-content/themes/mytheme/js/hoverintent.js.

Then, add the following to your theme's functions.php file:

function enqueue_hoverintent {
    //Add the script and jquery-ui to the generated header.
    wp_enqueue_script(
        'my_hoverintent', 
         get_stylesheet_directory_uri() . '/js/hoverintent.js', 
         array('jquery-ui-core')
    );

    //Add the jqueryui css file from Google's CDN since it isn't included with WP
    wp_enqueue_style (
        'googlecdn_jqueryui_style',
         'https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/themes/smoothness/jquery-ui.css',
    );
}

add_action( 'wp_enqueue_scripts', 'enqueue_hoverintent' );

Upvotes: 1

Related Questions