My current solution is to create a directory outside the child theme that includes the CSS, JS, and php files for customizations
This is a plugin, a folder containing PHP/JS/CSS, with a comment at the top of one of the PHP files that has /** Plugin Name: XYZ
at the top of the file.
<?php
/**
* Plugin Name: XYZ
*/
and then reference those in the child theme.
This isn’t needed. You can provide a hook/action/filter or use the existing hooks and filters WP provides. Including files directly from outside of the themes folder is bad practice and should never be necessary. In the long run it causes maintenance problems.
Edit: I don’t now ahead of time what customizations are needed. So the system needs to be very flexible and open-ended.
If you don’t know then you can’t know what to do, but that’s okay. At some point you will need to update the child theme, and adding hooks is always good. The parent theme might do this too. Otherwise it’s an unreasonable requirement, you can’t know what you don’t know.
Custom JS and CSS
If you want to add extra javascript files and stylesheets to a theme without modifying the theme, you can do that in a plugin. Just enqueue the styles and scripts as you normally would.
WordPress doesn’t see any difference between a style enqueued by a parent theme or a plugin, or itself. It’s all just code that has been loaded into memmory. There is no such thing as a plugin script, or theme style, and no sandboxing, so nothing prevents you adding extra styles and scripts this way.
Perhaps if you wanted to add inline code tags I could understand, but there are APIs for this, e.g. wp_add_inline_script
. If you really had to add it directly, there’s hooks such as wp_head
of wp_footer
etc to do it on.
Custom PHP
A plugin is by definition custom PHP. You can execute any custom PHP using a plugin.
If you wanted to replace a template with a new template from your plugin, you can do that too with the right filter. WooCommerce does it, lots of plugins do it, overiding specific templates or adding subfolders.
So use a plugin!