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 making a framework parent theme and in the parent functions.php, I want to register all the possible js files I use frequently and if I want it to load it, in the child functions.php I just have to use wp_enqueue_script().

But it doesn't work...

Any clue why?

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

The child functions.php file loads before the parent functions.php, so you're registering them after enqueueing them. Try enqueueing the scripts on a hook, like 'after_setup_theme' instead.

share|improve this answer
    
Nice gonna tcheck this right now!!! –  Eduplessis Aug 23 '10 at 21:00
    
Thanks working perfectly... but I put it on the 'init' hook –  Eduplessis Aug 23 '10 at 21:08
    
I'll still advise against splitting things up like this - registering scripts in the parent file and enqueuing them in the child file might work for your uses, but it makes it more difficult on developers who come along later and want to build a new child theme - they have to reproduce all of you enqueuing code to make it work. A child theme is supposed to modify the parent, not reproduce the parent's original child theme ... –  EAMann Aug 23 '10 at 21:10
add comment

It's bad form to split your code like that. You should always have your functions and the hooks that call them located in the same location to make it easier to debug.

That said, if you place your wp_enqueue_script() calls in the parent theme's functions.php file, do things work like they're supposed to? If not, there might be something else going on ... and we'd need to see your code to diagnose and fix it.

share|improve this answer
    
In general I agree with your comments about bad form but I think it doesn't apply in this use-case. What he @Eduplessis is doing in his parent theme is essentially the same that WordPress does in wp_default_scripts() in /wp-includes/script-loader.php; i.e. he's registering his custom scripts using wp_register_script() so his child themes need only call the simpler form of wp_enqueue_script() instead of having to specify the script's full file name and path from the parent's theme directory. FWIW. –  MikeSchinkel Aug 23 '10 at 23:18
    
I agree that the pattern has its uses ... but I'm coming from the background of having to debug poorly documented child themes and trying to help clients figure out when different functions are called on their site. Since wp_register_script and wp_enqueue_script work together, having them in different files can make it incredibly hard to track things down later. –  EAMann Aug 24 '10 at 1:34
    
thanks for your comments. A themes framework without any documentation is bad... or any project in gen. but since this themes framework it's only to speed up my developpment and I always make a little doc... i think it's the right choice to put all register all my script in my parent and the specific load in child... exactly like WordPress do with all js included by default. –  Eduplessis Aug 29 '10 at 7:32
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.