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.

Let's assume that twentythirteen/shortcodes/ exists and inside are folders with shortcodes. 1 folder = 1 shortcode. Each shortcode has: 1 PHP file, 1 CSS file, 1 JS file.

twentythirteen/shortcodes/load.php exists that does scandir() and wp_enqueue_script() for each JS and CSS file. Furthermore, it has an option to generate twentythirteen/shortcodes/style-cache.css and enqueue only this one (or all JS and CSS files individually).

The structure described above makes it very neat and modular but this will not work with Child Themes? Is there any way to make it work like that? It makes a lot of sense to have 1 folder with 1 CSS file, 1 JS file and 1 PHP file for each shortcode, don't you think?

share|improve this question
    
The short answer is: never define shortcodes in a theme. –  toscho Jun 6 '13 at 14:39
    
What if those are modules (separate libraries with separate JS file and separate CSS file) and it makes more sense to put them in a folder rather than put everything into main style.css? This isn't only about shortcodes. –  Paul Jun 6 '13 at 14:43

1 Answer 1

up vote 2 down vote accepted

Putting aside the question of what should and should not be part of a theme, I don't see why something like this wouldn't work with a child theme. Use get_stylesheet_directory, which will return the child theme path if it exists and otherwise will return the parent path, to build the path for scandir and I don't see the problem.

share|improve this answer
    
I tried that already and indeed it works but it requires extra consideration of Child Themes - which is (a) files can't be merged into style-cache.css by the theme because this big file with all shortcodes would have to be dequeued in a child theme, (b) loader.php needs to create nice hooks and use get_stylesheet_directory and (c) Child Theme should always contain loader.php that will overwrite only necessary files (that exist). This creates nicer structure but requires additional theme development work and still I'm not sure about drawbacks and if theme devs should really do this or not. –  Paul Jun 7 '13 at 16:19

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.