I am developing a child theme based on the roots theme. I created a front-page.php and added the following. I test that the page is loaded because I see the I am loaded text. However, the scripts are not loaded. What is wrong with my setup?

function dd_register_scripts() {
        get_template_directory_uri() . '/assets/js/something.min.js', array('jquery'), null, false

function dd_enqueue_scripts() { 

add_action('init', 'dd_register_scripts');
add_action('wp_enqueue_scripts', 'dd_enqueue_scripts');
<div id="asd">I am loaded</div>

1 Answer 1


Based on your description that you "created a front-page.php and added the following" and also that there is markup in that file, you are hooking too late.

You should be both registering and enqueueing on wp_enqueue_scripts but that isn't the problem here. The problem is that by the time you try to hook, the hooks have already fired. init will fire before your templates load at all and wp_enqueue_scripts will fire in the page header, which is before this code runs (or you have very broken markup). You can't hook to a hook after it has fired.

You need to add this code to the theme's functions.php with the appropriate template tags to conditionally load the scripts.




Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.