0

This has been giving me fits. I've been trying to build my first custom theme and I'm stuck pretty early on... I've been following tutorials and checking the Wordpress Codex, but I'm pretty new to this. It's not including a stylesheet at all, and when I try to include the js, I get an error "This Page Isn't Working".

<?php

function jw_script_enqueue() {

wp_enqueue_style('custom-style', get_template_directory_uri() . '/css/jw-custom.css', array(), false, 'all' );
we_enqueue_script('custom-js', get_template_directory_uri() . '/js/jw-custom.js', false, true)

}

add_action( 'wp_enqueue_scripts', 'jw_script_enqueue');

Here is my header:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>JW Custom</title>
        <?php wp_head(); ?>
    </head>

    <body>

and here is my footer:

        <footer>
            © 2018 JW Custom
        </footer>

        <?php wp_footer(); ?>
    </body>
</html>

My filepaths are correct. Any help would be greatly appreciated. What should I change?

1
  • For one, there's a typo in wp_enqueue_script. You've got we instead of wp Commented Jun 19, 2018 at 16:25

1 Answer 1

1

First thing's first, make sure your file locations are accurate, and you're not getting 404 errors in your console.

That said, you've got a typo, we_enqueue_script should be wp_enqueue_script - and you may actually be getting an undefined function error.

You also don't need to include the additional arguments in the wp_enqueue_ functions, and you're missing the $deps argument in your scripts call.

Also, unless you're building a parent theme, you may want to stick with get_stylesheet_directory_uri() instead of get_template_directory_uri().

Lastly, custom-script isn't a unique enough handle and you may actually be getting conflicts from a plugin or parent theme if it's active.

Try the following:

add_action( 'wp_enqueue_scripts', 'jw_script_enqueue');
function jw_script_enqueue() {
    wp_enqueue_style( 'jw-custom-style', get_stylesheet_directory_uri() .'/css/jw-custom.css' );
    wp_enqueue_script( 'jw-custom-js', get_stylesheet_directory_uri() .'/js/jw-custom.js );
}
Sign up to request clarification or add additional context in comments.

1 Comment

These solutions worked beautifully, thanks for the help!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.