Headless WordPress – Plugin path issues

Hello!

I’ve just begun working on my first ever headless site, backend will be handled by WP and frontend will be done with GatsbyJS.

Setting up as I usually do with Bedrock, I installed WP on a subdomain (admin.mydomain.com) with the idea that the frontend will live on mydomain.com.

After the installation finished, permalinks etcetera in the backend pointed towards admin.mydomain.com, and I wanted to have the permalinks point to the frontend instead, so I dug into my .env file and made some changes:

WP_HOME='http://admin.mydomain.test'
WP_SITEURL='http://admin.mydomain.test/wp'

became

WP_HOME='http://mydomain.test'
WP_SITEURL='http://admin.mydomain.test/wp'

and that successfully fixed my permalinks. However, now I get some console errors in the backend, some plugins are looking for resources that they can’t find with this config. For example, ACF complains:
GET http://mydomain.test/app/plugins/advanced-custom-fields-pro/assets/css/acf-global.css?ver=5.8.4 net::ERR_NAME_NOT_RESOLVED

I’m wondering what the proper course of action is here. It seems that WP_PLUGIN_URL might should be changed somehow, but I’m not sure if that’s the best way to do it. Curious what other people have done in this situation.

Ok, so here’s my fix for the issue.

  1. in .env add WP_HOME_ADMIN='http://admin.mydomain.test'
  2. in application.php, after Config::define('WP_HOME', env('WP_HOME')); add this line: Config::define('WP_HOME_ADMIN', env('WP_HOME_ADMIN'));
  3. after the line Config::define('CONTENT_DIR', '/app'); add this: Config::define('WP_PLUGIN_URL', Config::get('WP_HOME_ADMIN') . Config::get('CONTENT_DIR') .'/plugins');

Surely some better solution out there, so please post if you have another way :slight_smile:

Also: Maybe some proper way to do this should make it’s way into Bedrock core at some point? I think decoupled solutions are just gonna get more and more popular.

3 Likes

This topic was automatically closed after 42 days. New replies are no longer allowed.