Sometimes we need to write some duplicate functions/classes
to the themes and include in functions.php
for a custom template. I decided to create a directory called inc
(for example: wp-content/themes/A/inc
) and build my classes there and include
it in functions.php.I also created the autoload
class.
// functions.php
include WP_DIR . '/inc/autoload.php';
But there is a problem. When I want to create another template(into wp-content/themes
), I have to create the inc
(for example: wp-content/themes/B/inc
) directory again and copy the previous classes and autoload.php
. In fact, templates use several duplicate common classes
.
- What do you suggest to prevent rewriting?
- Is it possible to write these classes(autoload.php, …) as a plugin in the
wp-content/plugins
directory and enable it? Does it make sense? Is this correct? - Can I create a directory within the theme directory for shared classes?
- What is the WordPress solution to this issue?