rahilo
rahilo

Reputation: 11

Javascript in Wordpress

Im new to wordpress and im trying to load javascript to it. This is my functions.php

add_action('wp_enque_scripts',function(){
    wp_enqueue_script('$javascript', get_stylesheet_directory_uri(). 
    'javascript/javascript.js', [], false, true);
});

and this is my javascript.js

console.log("hi");

When i open my browser's console i cant see the printed message. Plus my script file link isnt loaded in the HTML. What might be wrong? Is it that i didnt specified the javascript version?

Upvotes: 1

Views: 49

Answers (1)

Pof
Pof

Reputation: 979

Your mistake is in your action name wp_enque_scripts. You should write wp_enqueue_scripts

In addition, I think you need a slash before your folder name

add_action('wp_enqueue_scripts',function(){
    wp_enqueue_script('$javascript', get_stylesheet_directory_uri(). 
    '/javascript/javascript.js', [], false, true);
});

Upvotes: 2

Related Questions