0

So, I've not used Wordpress in a long time, and I'm trying to get back into the swing of things. Apparently the correct way to deal with external CSS/JS is to enqueue them using wp_register_style, wp_enqueue_style, wp_register_script, and wp_enqueue_script... but they're not working for me at all.

The following is my current functions.php:

<?php

    // Enqueue necessary scripts/etc.
    function wasd_styles() {
        wp_register_style('semantic-css', get_stylesheet_directory_uri() . '/lib/semantic.min.css');
        wp_enqueue_style('semantic-css');
    }

    function wasd_scripts() {
        wp_register_script('semantic-js', get_template_directory_uri() . '/lib/semantic.min.js');
        wp_enqueue_script('semantic-js');
    }

    add_action('wp_enqueue_scripts', 'wasd_styles');
    add_action('wp_enqueue_scripts', 'wasd_scripts');

?>

Is there something I'm doing wrong? As far as I can tell, it should be injecting the proper calls to grab CSS/JS into the tag of my page, but..it's not.

The following are the two files I'm attempting to render, I threw this together in like 5 minutes to attempt to test Semantic UI, but it's just not working at all, no style is being rendered, and is empty upon source inspection.

index.php

<?php get_header(); ?>

<div class="ui main container">
    <h2 class="ui dividing header">This is a test</h2>
</div>

header.php

<div class="ui top fixed inverted menu">
    <div class="item">Test</div>
</div>

1 Answer 1

1

From the code you have shared, your theme does not support the use of wp_enqueue_script(). This function simply registers the scripts and gets it ready for insertion into the DOM. This is inserted via a hook, which doesn't appear to be present in your theme. You would need to add the following into your header.php file. This would typically be added between the <head></head> tags.

<?php wp_head(); ?>

Also, you should have a similar hook in your footer.php file, typically just before the closing </body> tag. This hook would be:

<?php wp_footer(); ?>

Without these, wp_enqueue_script() and wp_enqueue_style() will not work.

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

2 Comments

Since I posted my self-answer at the same time you posted this, I'll accept yours as the answer, because it was indeed my problem. I'm pretty new to WP, and just overlooked it. Thank you very much for your quick response.
Thanks. Happy coding!

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.