kuroi
kuroi

Reputation: 15

Including my JavaScript file in Wordpress doesn't work

My js works as I have tested it in codepen but since it doesn't work on my site I think the problem must lie in my flawed knowledge of wp-functions. After reading through articles and similar questions on this topic I arrived at this code but it doesn't seem to load. I'm trying to get it to work in my child theme if that's any help.

I'm thankful for any advice

function my_js_script(){
    wp_deregister_script( 'jquery' ); 
    wp_register_script('jquery', ("https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"), false);
    wp_enqueue_script('jquery');
    wp_register_script('my', get_stylesheet_directory_uri() . '/js/my.js', array('jquery') );
    wp_enqueue_script('my'); 
}

add_action( 'wp_enqueue_scripts', 'my_js_script' );

Upvotes: 0

Views: 37

Answers (1)

dubplay
dubplay

Reputation: 83

You cannot deregister jQuery. It is likely your plugin is excepting at that line.

Try looking at this WordPress StackExchange question.

Upvotes: 1

Related Questions