Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm trying to create a child theme based on Toolbox 1.4 by Automattic.

I have my scripts file saved as child_theme/js/scripts.js on my server and I enqueue it by using

wp_enqueue_script( 'scripts', get_stylesheet_directory_uri() . '/js/scripts.js', array('jquery') );

in the header.php.

When I view source in Firefox, I see the href to the stylesheet as

http://example.com/wordpress/wp-content/themes/child_theme/style.css

and the href to the scripts as

http://example.com/wordpress/wp-content/themes/child_theme/js/scripts.js?ver=3.3.2

When I click on both, I can see the source of my style.css, but it says "Page not found" for my scripts.js.

I've never created a child theme before. I used to just copy a theme and modify it. What am I doing wrong?

EDIT

It works when I move scripts.js out of the /js/ subdirectory into the child theme's root directory and change the wp_enequeue_script. So what is wrong?

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

Shouldn't you be enqueuing that in functions.php instead?

function script_enqueueing() {
    wp_enqueue_script(
        'scripts',
        get_stylesheet_directory_uri() . '/js/scripts.js',
        array('jquery')
    );
}
add_action('wp_enqueue_scripts', 'script_enqueueing');

Edit to add: if calling directly in header.php, use get_template_directory_uri(); instead.

share|improve this answer
    
You may be right about putting it in the functions.php, but I still get 404 if the scripts.js is in a subdirectory. –  gavsiu Apr 30 '12 at 23:14
    
Actually I don't know what the deal with the problem is. I just keep reloading the page and now it works. =/ –  gavsiu Apr 30 '12 at 23:20
    
When you change theme files at all, make sure you're flushing your cache (and emptying your W3 cache if you're using it). On Windows it's generally CTRL+F5 instead of just F5, or on Chrome/Firefox start a private/incognito session to make sure you're not seeing old content. I'm glad it's working though! –  SickHippie May 1 '12 at 16:40
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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