How to Include a WordPress Plugin in a Non-WordPress Project?

Short answer: You can’t.

The long answer is complicated and should be avoided if possible. That said, there are always workarounds…

Rewrite the plugin

The most viable (and rightful) option is often rewriting the core logic of the plugin. It’s the most time consuming one, but it doesn’t depend on the WordPress Core.

Plugins tend to rely on a huge pile of WordPress Core code and its APIs so it’s usually a hassle.

Load the WordPress Core

It’s possible to set up a clean WordPress install in a subfolder and include wp-load.php on top of your plugin. It won’t work for every plugin and it will effectively load the entire WordPress Core. But simple plugins may work this way.

That said, it’s just loading the WordPress Core altogether. But you can limit it to a single endpoint or a callback – instead of loading WordPress for each and every HTTP request.

Port Certain APIs

You will almost inevitably hit some limits and a number of dependencies along the way. But some APIs are lightweight and somewhat decoupled – such as the HTTP API, the XML-RPC specification, the RSS feeds.

Running cachegrind or another debugger may help you browse the entire stack that a plugin requests. For instance, you can set up a basic front-end page with a lightweight header/footer and inject your plugin function there, finding out what gets loaded and triggered along the way.

WordPress REST API

WordPress has designed and incorporated a REST API some three years ago. You can set up a WordPress install elsewhere, blacklist most requests and open a certain endpoint loading your plugin code. IP whitelisting for your server would avoid some DDoS attacks, too.

Iframes

For plugins loading some code on the front-end, adding an iframe to your website embedding a generated screen off of WordPress may work. It will impact your SEO but it’s an option.

A custom extension/add-on

You can set up WordPress, your plugin, and a custom extension extracting whatever you need and passing it through REST/SOAP in a way that your site can parse and render.

You can generate the HTML output, a JSON data array, or new endpoints for adding and fetching data as needed.

Again, it’s far from ideal, but you want to support a tiny extension relying on 300,000+ lines of code.


Part of:

My name is Mario Peshev, a global SME Business Advisor running digital businesses for 20 the past years.

Born in Bulgaria, Europe, I gained diverse management experience through my training work across Europe, North America, and the Arab world. With 10,000+ hours in consulting and training for organizations like SAP, VMware, CERN, I’ve dedicated a huge amount of my time to helping hundreds of SMEs growing in different stages of the business lifecycle.

My martech agency DevriX grew past 50 people and ranks as a top 10 WordPress global agency and Growth Blueprint, my advisory firm, has served 400+ SME founders and executives with monthly ongoing strategy sessions.


Follow me at:

Latest Editions:

Browse by Category

Latest Answers: