0

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' );

1
  • I tried putting the script directly in the theme-header via plugin, that doesn't work either so maybe the code is corrrect and the problem lies elsewhere Commented Mar 17, 2020 at 17:19

1 Answer 1

1

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

Try looking at this WordPress StackExchange question.

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

1 Comment

Deregistering jQuery isn't really my problem since wordpress comes preequipped with it. I just added that since it didn't work the first time. I'm getting an error in the console so it seems to have registered and that the problem strangley lies in the javascript even though it works on its own

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.