I can’t enqueue my scripts – They literally aren’t being added to my site

Question

Ok, I’ve literally copy-pasted different enqueueing code from about 5 different sources (Including wordpress), and not a single one works.

Here’s the code I’m using in functions.php:

<?php

function my_theme_scripts() {
    wp_register_script(
        'main',
        get_stylesheet_directory_uri() . '/js/main.js',
        array( 'jquery' ), '1.0.0', true
    );
    wp_enqueue_script('main');
}

add_action( 'wp_enqueue_scripts', 'my_theme_scripts' );

?>    

and it literally does nothing. No scripts added into my HTML. nothing.

This is my first time using wordpress, and nobody has explained the functions file to me completely right, but from my understanding, i don’t do anything like do I?

I’ve also put <?php wp_footer(); ?> right before </body> if that means anything.

EDIT:
I’ve solved the problem

Stupidly, I’d forgotten to add <?php wp_head(); ?> right before </head>, this screwed it all up. I also changed the ‘main’ identifier to something more unique, which didn’t change anything but might be a better practice anyway.

0
, , , Billy Ray Cyrus 1 year 2020-07-13T21:13:13-05:00 0 Answers 76 views 0

Leave an answer

Browse
Browse