I am developing a WP theme which I'm referring to as foobar for the sake of this question. It's located in /var/www/html/wp-content/themes/foobar. At the moment, I am activating it via wp-admin webpage and changes go live as soon as I save the corresponding files which is the desired behavior.

Now, I want to use wp-cli to activate my theme in order to streamline deployment. However, so far, I've been unable to do so:

$ wp theme activate foobar
Error: Stylesheet is missing.

This is confusing as the stylesheet does exist:

$ file  /var/www/html/wp-content/themes/foobar/style.css
/var/www/html/wp-content/themes/foobar/style.css: ASCII text, with CRLF line terminators

When I look at theme list, it doesn't show foobar:

$ wp theme list
| name            | status   | update | version |
| twentyfifteen   | active   | none   | 2.0     |
| twentyseventeen | inactive | none   | 1.7     |
| twentysixteen   | inactive | none   | 1.5     |

I verified that foobar is displayed in wp-admin and I could activate it via a click of the button. Theme list after activating foobar:

$ wp theme list
| name            | status   | update | version |
| twentyfifteen   | inactive | none   | 2.0     |
| twentyseventeen | inactive | none   | 1.7     |
| twentysixteen   | inactive | none   | 1.5     |

Searched Github wp-cli issues and on this StackExchange but couldn't find anything that seemed relevant. I cannot host the theme in Wordpress.org and prefer not to zip it up as that would hamper development velocity. Perhaps I'm missing something obvious here.

My questions:

  1. Why does wp-cli not see my theme but wp-admin does?
  2. Possibly related to the previous question: Why is it complaining about stylesheet missing when it's there?
  3. What would be the best way to activate a theme that is on the local disk for development with minimal friction (i.e., preferably, not requiring re-zip after changes)?
  • Which folder are you running those commands in? Where you run wp cli is important but it's not clear what the working directory is. Additionally have you confirmed that style.css is indeed well formatted with the appropriate header? – Tom J Nowell Aug 16 '18 at 23:06
  • Haven't kept track. I'll try it on a few different working directories and see if it makes a difference. Thanks for the tip. – Belmin Fernandez Aug 16 '18 at 23:07
  • Can you edit your question with that information? WP CLI needs to be ran in the same working directory as the install of WP. If you run it elsewhere you'll get different results – Tom J Nowell Aug 16 '18 at 23:08
  • Will append as soon as I experiment. In the meantime, I didn't see any documentation pointing to the CWD being relevant. Assuming this is only relevant for commands that involve local disk artifacts? E.g., theme list seems to just use the the WP config to enumerate themes. – Belmin Fernandez Aug 16 '18 at 23:17
  • It's relevant in the same way it is to ls, servers can have more than 1 WP install and WP CLI needs a way of finding out where the WP install is, so it assumes the place the user is in. Otherwise it would need to do a full search of the filesystem on every command issued which could take hours. E.g. if you run WP CLI from the home folder I would not expect to see themes listed, and instead see complaints. It might even be that you were running WP CLI on a temporary copy of WP from when you first setup the server, who knows – Tom J Nowell Aug 16 '18 at 23:19

[S/O to @TomJNowell whose comments helped me track down the issue. Sharing in case it could help others troubleshoot a similar problem]

In my setup, I'm using two Docker containers with different images:

  • wordpress:4.9: wp container
  • wordpesss:cli: wp-cli container

In order to allow wp-cli container access to the Wordpress config, files, etc., I configured them to share a named volume mounted to /var/www/html/.

For the most part, this worked as intended. However, I discovered that the volume mount /var/www/html/wp-content/themes/foobar -> (local theme dir) was only configured for the wp container and not wp-cli. This makes sense of why wp command:

  1. Couldn't find the stylesheet
  2. Wasn't listing the local theme

When I was verifying that the theme directory existed, I was only looking at the wp container and not wp-cli as I assumed both had the same volumes mounted.

Once I modified the docker config and mounted the theme directory on wp-cli, everything worked as expected.

Note: Once I discovered my mistake, tested the command in multiple CWD, including root (/). Each time I received the same results.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.