Where should I install a PHP library into WordPress so that code in a webpage can activate it?

The best way would be to create a custom plugin for your site. Take a look at the plugin handbook to get started
https://developer.wordpress.org/plugins/

In the plugin, you can just put the libraries in a folder, and include them in your main plugin code. Your plugin can then do one of these

  1. Register a shortcode
  2. Create a custom template tag, which would be just a function that outputs your content, and can be used in any other php file in your site.
  3. Create a block for the new block editor

Technically it’s possible to just put this in your theme, but it’s advised to put any custom code like this in a plugin for better maintenance, and ease of changing themes in the future.

Leave a Comment