Changing WordPress's core `wp` directory

I’ve been playing with trellis + bedrock and really enjoying the structure and setup. However, from prior installation configurations I would install the WordPress core files into a folder called cms, rather than the folder called wp (the more obscurity, the better, I figured at the time).

So far I have renamed all the wp folder references in:

  • trellis/group_vars/all/helpers.yml
  • trellis/group_vars/*/wordpress_sites.yml
  • example.com/wp-cli.yml

… but I notice that the wp folder reference itself is hard-coded into example.com/web/index.php. Would there be any possibility or scope in the future to automate changing the core wp folder name/location?

It looks like there’s two more references in Trellis: roles/wordpress-setup/templates/wordpress-site.conf.j2

I’d be open to making Trellis not entirely dependent on Bedrock or making it configurable. But the main issue is those other files you mentioned aren’t part of Trellis, they are part of Bedrock.

So you can fork Bedrock and set it whatever you want, then customize Trellis.

Perhaps the core folder name could be an option in the wordpress_sites.yml files for trellis, that these .conf.j2 files could reference — that’s probably easy enough for me to fork and make a pull request.

On the current project I’m managing I’m running two (bedrock) WordPress sites from a single machine managed by trellis, so supporting key automated differences between each WP instance, such as the WP core folder name, would be ideal in the trellis setting.

Well, I originally got around this with a quickfix, but when it came to deployment I had to trawl through all the code again (using Trellis 0.9.9). There are a number of different spots where you have to manually set the custom WP core folder name. I’m unsure how to automate this outside the YML/J2 files so had to do it by hand for everything else:

  • site/wp-cli.yml
  • site/composer.json
  • site/config/application.php
  • site/web/index.php
  • trellis/group_vars/development/wordpress_sites.yml
  • trellis/group_vars/staging/wordpress_sites.yml
  • trellis/group_vars/production/wordpress_sites.yml
  • trellis/roles/wordpress-install/tasks/main.yml
  • trellis/roles/wordpress-setup/templates/wordpress-site-conf.j2

Just to clarify again, the following are in Bedrock:

site/wp-cli.yml
site/composer.json
site/config/application.php
site/web/index.php

Next up is the variables in Trellis:

trellis/group_vars/development/wordpress_sites.yml
trellis/group_vars/staging/wordpress_sites.yml
trellis/group_vars/production/wordpress_sites.yml

These are meant to be customized. Obviously we need to have the defaults somewhere.

So in Trellis there’s really only two “hardcoded” references:

trellis/roles/wordpress-install/tasks/main.yml
trellis/roles/wordpress-setup/templates/wordpress-site-conf.j2

These are the two things that could be done a little better.

Ah yes, you’re right. I keep forgetting about Bedrock being there!

In terms of the trellis references I’ve added a wp_install_dirname entry in my group_vars/*/wordpress_sites.yml which can then be used in the other trellis files, but it’s the bedrock side which is a little harder, mostly because of site/web/index.php, since all the config stuff is loaded/required after that file.

The other thing I found is with the site/wp-cli.yml that if you use the --path="path/to/wp/core" flag in wp core install task in trellis/roles/wordpress-install/tasks/main.yml that it fails if it is different to the site/wp-cli.yml path. Is there some way that this could be automatically generated during the WP install if the core directory is different? I’m not entirely sure how the path could be changed in the composer.json — and maybe it is well out of scope of this particular task anyway, since you only need to edit/set it all once before deploying?

(Edit: actually, I think it fails if the composer.json wp path isn’t set properly since composer downloads and installs the core files first and the the wp-cli uses the downloaded core location to install the site)

I change in these files but still not works.

After i change web/wp to web/backend.
I faces ‘too many redirection’.

Did we really able to change the directory name?

Submitted this issue here

Same here. I changed it to /core and now it’s redirecting to /core/wp/… Tried to find the source of this for a couple of hours but wasn’t lucky.