How do I get my Javascript scripts working?

I am reading through the developer site for WordPress and am just at the beginning of my learning of it. I have gotten my CSS to work via the wp_enqueue_style() but my javascript won’t work via the wp_enqueue_script().

I have not added any Javascript on the pages themselves, I have the functions.php file with the wp_enqueue_script() in it which points to my /js/functions.js file where I want the toggleNav() function to work in for displaying the navigation menu differently on mobile.

What am I doing wrong? Here is my code:



function my_theme_scripts(){
wp_enqueue_style( ‘style’, get_stylesheet_uri() );

wp_enqueue_script( ‘functions’, get_template_directory_uri() .
‘js/functions.js’, array(), ‘1.1’, true );

add_action( ‘wp_enqueue_scripts’, ‘my_theme_scripts’ );



function toggleNav() {
var nav = document.getElementById(“navbar”);
if (! || === “none”) { = “block”;
} else { = “none”;


I’ve even tried placing a function call in the footer.php but it doesn’t work.
When I add the javascript directly into the footer.php file it does work though.

Read more here:: How do I get my Javascript scripts working?

Leave a Reply

Your email address will not be published. Required fields are marked *