Title: Add a code library for use in multiple modules?
Last modified: September 19, 2026

---

# Add a code library for use in multiple modules?

 *  [petercode](https://wordpress.org/support/users/petercode/)
 * (@petercode)
 * [1 week, 4 days ago](https://wordpress.org/support/topic/add-a-code-library-for-use-in-multiple-modules/)
 * I have tow libraries of code for use in more than one module I want to develop.
   Can I create an add on module that makes the library available to other modules
   or do I have to add the code to every module?
 * Both libraries have a base bit of code to create autoloading for that library.
   Directory example contains example.php and sets up autoloading for the example
   directory. Every file in the directory is a class named example_* in file example_*.
   php.
 * The modules using the Example library would list the Example module as a prerequisite
   and need only a way to load example.php then all the classes in example would
   be autoloaded.
 * I just need a pointer to a module already doing this or a documentation page.
   I have experience creating WordPress modules. For this task, my Internet searches
   have not produced a starting point.
 * If sharing a library across modules is not legal, what is the recommended way
   to add the library unmodified so I can maintain the library in Github and just
   download the updated library direct into the module code as is?

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Moderator [threadi](https://wordpress.org/support/users/threadi/)
 * (@threadi)
 * [1 week, 3 days ago](https://wordpress.org/support/topic/add-a-code-library-for-use-in-multiple-modules/#post-19023986)
 * I would advise against making these libraries available in separate plugins. 
   It’s technically possible, yes, but it makes it harder for your users to keep
   track of everything.
 * My recommendation would be to work with Composer packages instead. Make whatever
   you want to use repeatedly available as a Composer package and install it via
   Composer in every plugin before you publish it. This allows you to manage all
   your libraries centrally while still using them in every plugin you create.
 * That’s exactly how I do it, and I’ve already made several Composer packages available
   to other developers as well. Of course, you don’t have to do this, but in my 
   opinion, that’s the approach you should take.
 *  [Ahmad](https://wordpress.org/support/users/allen32/)
 * (@allen32)
 * [1 week, 3 days ago](https://wordpress.org/support/topic/add-a-code-library-for-use-in-multiple-modules/#post-19024119)
 * **A separate library plugin.** Put your autoloader in its own plugin. Since WordPress
   6.5 your other plugins can declare it as a dependency in their header:
 * `Requires Plugins: example-library`
 * WordPress then requires the library plugin to be active before the dependents.
   Details are in the Plugin Handbook under “Header Requirements”. Note that the
   slug is matched against the WordPress.org directory, so for a private or GitHub-
   hosted plugin you’d need the `wp_plugin_dependencies_slug` filter, or check `
   class_exists()` yourself on `plugins_loaded`.
 *  Thread Starter [petercode](https://wordpress.org/support/users/petercode/)
 * (@petercode)
 * [1 week, 3 days ago](https://wordpress.org/support/topic/add-a-code-library-for-use-in-multiple-modules/#post-19024291)
 * Thank you for the suggestions. I will experiment over the next few weeks.
 *  [prateekshawebdesign](https://wordpress.org/support/users/prateekshawebdesign/)
 * (@prateekshawebdesign)
 * [1 week, 2 days ago](https://wordpress.org/support/topic/add-a-code-library-for-use-in-multiple-modules/#post-19024475)
 * Hi [petercode](https://wordpress.org/support/users/petercode/)  Welcome to the
   WordPress community!
 * I’ve used shared libraries across multiple projects, and I’d also recommend **
   Composer** rather than creating a separate plugin just for the library.
 * I’d keep the library in its own GitHub repository, make it a Composer package,
   and include it as a dependency in each plugin. That way I can maintain the library
   in one place, version it properly, and update individual plugins when needed.
 * Another advantage is that each plugin remains self-contained after deployment.
   I don’t have to worry about whether another plugin containing the shared library
   is installed or active, which makes maintenance and troubleshooting much easier.

Viewing 4 replies - 1 through 4 (of 4 total)

You must be [logged in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fadd-a-code-library-for-use-in-multiple-modules%2F%3Foutput_format%3Dmd&locale=en_US)
to reply to this topic.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 4 replies
 * 4 participants
 * Last reply from: [prateekshawebdesign](https://wordpress.org/support/users/prateekshawebdesign/)
 * Last activity: [1 week, 2 days ago](https://wordpress.org/support/topic/add-a-code-library-for-use-in-multiple-modules/#post-19024475)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
